SophiaPretty

(5)

$14/per page/Negotiable

About SophiaPretty

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Accounting,Algebra See all
Accounting,Algebra,Applied Sciences,Architecture and Design,Art & Design,Biology,Business & Finance,Calculus,Chemistry,Communications,Computer Science,Economics,Engineering,English,Environmental science,Essay writing Hide all
Teaching Since: Jul 2017
Last Sign in: 305 Weeks Ago, 1 Day Ago
Questions Answered: 15833
Tutorials Posted: 15827

Education

  • MBA,PHD, Juris Doctor
    Strayer,Devery,Harvard University
    Mar-1995 - Mar-2002

Experience

  • Manager Planning
    WalMart
    Mar-2001 - Feb-2009

Category > Computer Science Posted 04 Jan 2018 My Price 10.00

/* Returns 1 if the ship is operational; 0 otherwise */

Could you take a look of this c language project?

Its a very simple battleship project but I have no idea how to get it done.

  • #ifndef __LIB_BATTLESHIP__
    #define __LIB_BATTLESHIP__

    struct battleship {
        int *body;     /* pointer to an array */
        int size;      /* battleship size */
        int pos;       /* battleship position */
    };

    /* Returns 1 if the ship is operational; 0 otherwise */
    int shipState(struct battleship ship);


    /* Print ship info */
    void shipInfo(struct battleship ship);


    /*
     * Makes a battleship with specified size at the specified position.
     * Initializes all elements of ship.body to 1.
     */
    struct battleship makeShip(int size, int pos);


    /*
     * Returns 1 if attackpos lands on a undamaged segment of a ship.
     * Registers damage to the hit segment.
     */
    int hitShip(struct battleship *ship, int attackpos);


    /* Return 1 if at least one ship is operational; 0 otherwise. */
    int fleetState(struct battleship *fleet, int numships);


    /* Handles attack event on fleet of ships given user's attack. */
    void attack(struct battleship *fleet, int numships, int attackpos);


    /* Makes a fleet from configuration file; sets boardsize and numships */
    struct battleship *setupGame(char *filename, int *boardsize, int *numships);


    /*
     * Game loop: reads attack positions from standard input, registers
     * damage on ships, indicates hit/miss events, indicates sunkin ship events,
     * and terminates when all ships are sunk.
     * Returns number of turns to sink all ships.
     */
    int playGame(struct battleship *fleet, int numships, int boardsize);


    #endif#include <stdio.h>
    #include "libbattleship.h"

    int main(void)
    {
        int shipSize = 3;
        int shipPos = 4;
        int attackPos = 5;
        struct battleship ship;

        ship = makeShip(shipSize, shipPos);
        shipInfo(ship); /* healthy ship */

        printf("Attack position %d!\n", attackPos);
        if (hitShip(&ship, attackPos) == 1)
            printf("Hit!\n");
        else
            printf("Miss!\n");
        shipInfo(ship); /* damaged ship */

        return 0;
    }
    #include <stdio.h>
    #include "libbattleship.h"

    int main(void)
    {
        int shipSize = 3;
        int shipPos = 4;
        int attackPos = 4;
        struct battleship ship;

        ship = makeShip(shipSize, shipPos);
        shipInfo(ship); /* healthy ship */

        /* damage each segment of the ship until it is destroyed */
        for (attackPos = ship.pos; attackPos < ship.pos + ship.size; attackPos++) {
            printf("Attack position %d!\n", attackPos);

            if (hitShip(&ship, attackPos) == 1)
                printf("Hit!\n");
            else
                printf("Miss!\n");

            shipInfo(ship); /* damaged ship */
        }


        return 0;
    }


Attachments:

Answers

(5)
Status NEW Posted 04 Jan 2018 07:01 AM My Price 10.00

-----------  ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly

Not Rated(0)