Thread: Help me finish this please

  1. #1
    Registered User
    Join Date
    Mar 2011

    Help me finish this please

    I have to Create a new project that consists of at least two classes: a base class and a derived class. It should also contain at least one more class that will be used to instantiate the composite member of either the base or the derived class.
    I have most of it but I think I need to have an overload somewhere and maybe a class with people but not sure what or how to implement it. Someone please help me.

    #include <iostream>
    #include <string>
    #include <iomanip>
    #include <fstream>

    using namespace std;

    class Gun

    int shotsFired;
    int hit;
    int miss;
    double hitPercent;
    string name;
    int ammo;

    virtual ~Gun();
    void shoot(int, double, int, int, int);
    void reload();
    virtual void print() = 0;
    virtual void damage();

    shotsFired = 0;
    hit = 0;
    miss = 0;
    hitPercent = 0.0;
    name = "Generic Gun";
    ammo = 0;
    Gun::Gun(int rounds)
    if (rounds >= 0)
    ammo = rounds;
    void Gun::shoot(int ammo, double hitPercent, int hit, int miss, int shotsFired)
    shotsFired = hit + miss;
    hitPercent = hit / shotsFired;
    miss = shotsFired - hit;
    cout << "Shots: " << shotsFired << endl;
    cout << "Hit %: " << hitPercent << endl;
    void Gun::damage()
    class MachineGun : public Gun
    void print();

    MachineGun::MachineGun() :Gun(30)
    name = "Machine Gun";
    void MachineGun::print()

    cout << "Your machine gun has " << ammo << " shots left." << endl;
    class Pistol : public Gun
    void print();

    name = "Pistol";
    void Pistol::print()
    cout << "Your pistol has " << ammo << " shots left." << endl;
    int main()
    MachineGun *mGun = new MachineGun();

    Pistol *mPistol = new Pistol();

    return 0;

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    Well you didn't read this on your way in
    << !! Posting Code? Read this First !! >>
    which is why your code is unreadable, and being ignored.

    It wouldn't do much good in your case anyway, since there is no indentation in the code anyway.

    It's quite often the case that such code is an indication of mindless copy and puke coding from someone not willing to put in any effort on their own.
    And lo, there is an almost identical post from a couple of years ago here
    Gun Program - C And C++ | Dream.In.Code
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. please help me finish my Hangman program (C)
    By eddybro in forum C Programming
    Replies: 1
    Last Post: 11-30-2010, 08:52 AM
  2. Please help me finish my assignment.
    By hayood in forum C Programming
    Replies: 2
    Last Post: 03-20-2010, 03:15 PM
  3. I never Finish my programs :(
    By epidemic in forum C++ Programming
    Replies: 11
    Last Post: 04-02-2007, 12:35 PM
  4. force finish
    By PUI in forum C Programming
    Replies: 1
    Last Post: 10-07-2006, 09:42 AM
  5. Game Programming FAQ
    By TechWins in forum Game Programming
    Replies: 5
    Last Post: 09-29-2004, 02:00 AM