Help on writing a code.

I'm VERY new at C++, and I have to write an application program that utilizes a car object. The void start should be called at the beginning to set private data items for the car constructor. The values set should be input from the user. The rest of the program should be menu driven with choices for driving a trip, adding gas, printing the car information, and quitting. The main program should prompt the user for the amount of gas and the distance of the trip when those choices are selected.
So far, I've only been able to write the header file.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
  class car 
{
      private:
		int mileage;
          double gas;
		double mpg;
		double tank_size;
      public:
		car ();
		void start (double m, double ts);
          void add_gas (double g);
          void drive (int m);
          void print ();
};


thats the header code, but now I dont know how I should start writing the actual source code. So far, I only have

1
2
3
4
5
6
7
8
9
10
11
12
13
14
// Main program that uses the Car class
#include <cstdlib>
#include <iostream>

using namespace std;

#include "car.h"

int main(int argc, char *argv[])
{


    return 0;
}


Does anyone have any tips or suggestions? I wrote a hockey program that's kind of similar if anyone can show me what steps to take from that code and how to do this one would be great.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// Main program that uses the Hockey class
#include <cstdlib>
#include <iostream>

using namespace std;

#include "Hockey.h"

int main(int argc, char *argv[])
{
    Hockey eichel, kane;

    eichel.initialize();
    kane.initialize();
    eichel.score_goal();
    eichel.score_goal();
    eichel.assist_goal();
    eichel.tripping();

    kane.assist_goal();
    kane.assist_goal();
    kane.assist_goal();
    kane.fighting();
    kane.fighting();

    cout << "Eichel stats: ";

    cout << "\n\nKane stats: ";

    cout << "\n\n";

    return 0;
}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <iostream>
using namespace std;

// Hockey class keeping track of a player's goals, assists,
// penalties and penalty minutes
class Hockey
{
      private:
        int goals,            // number of goals
            assists,          // number of assists
            penalties,        // number of penalties
            penalty_minutes;  // total of penalty minutes
      public:
         void initialize ();
         void tripping ();
         void fighting ();
         void score_goal ();
         void assist_goal ();
         void print ();
};

void Hockey::initialize()
{
    goals = assists = penalties = penalty_minutes = 0;
}

void Hockey::tripping()
{
    penalties++;
    penalty_minutes = penalty_minutes + 2;
}

void Hockey::fighting()
{
    penalties++;
    penalty_minutes = penalty_minutes + 5;
}

void Hockey::assist_goal()
{
    assists++;
}

// Records the fact that the player has scored another goal
void Hockey::score_goal ()
{
     goals++;
}

// Prints the player's current statistics
void Hockey::print ()
{
     cout << "\n\nGoals:   " << goals;
     cout << "\nAssists: " << assists;
     if (penalties == 1)
       cout << "\n" << penalties << " penalty for "
            << penalty_minutes << " minutes.";
     else
        cout << "\n" << penalties << " penalties for "
          << penalty_minutes << " minutes.";
}
Last edited on
Topic archived. No new replies allowed.