Hello forum,

I need help with my first assignment regarding classes.

I have no clue where to start so if possible could you please walk me through the best logical process to solve this assignment. I have no clue where to start so any information will help.

Here is what I need to do:
I need to define a class called odometer.
This class will track fuel and mileage for a car.
The class should have member variables to track the miles driven and the fuel efficiency of the car in miles per gallon.
Include a mutator function to reset the odometer to zero miles, a mutator function to set the fuel efficiency, a mutator function that accepts miles driven for a trip and adds it to the odometer's total, and an accessor function that returns the number of gallons of gas that the vehicle has consumed since the odometer was last reset.
Use your class with a test program that creates several trips with different fuel efficiencies. You decide which variables should be public if any.

I really have no idea where to start, please talk to me like a 2 year old because basically I am in C++.

I am not asking you to do the assignment I am asking for you to tell me how to do it/ what do do.

Thank you very much.

Here is how to define a class:

class nameOfClass{

// variables
int x;
string y;

// functions
int someFunction( float inputParameter);
};

Now you do it for odometer class.

Nothing much but heres what I have so far:

#include <iostream>
#include <cstdlib>

using namespace std;


//Class
class Odometer
{
public:
	void input();
	void output();

//private:
	int TrackMilesDriven;
	int MilesPerGallon;
	int Miles;
	double FuelEfficiency;
};

int main()
{
	Odometer miles, fuel;

	cout << "Enter in Miles Driven: ";
	cin >> miles.Miles;
	cout << miles.Miles << "\n" ; //test


        cout << "Enter in Fuel: ";
	cin >> fuel.FuelEfficiency;
	cout << fuel.FuelEfficiency << "\n"; //test

	system ("PAUSE");
	return 0;}

Now what should I do?

So a class is just like a struct???????

Nope, there's a visible difference between a structure and a class
structs have default public members and bases and classes have default private members and bases.

Read some articles regarding classes and structures

Edited 4 Years Ago by zeroliken: n/a

Ok. I will. I am new to programming but when i saw odometer miles and you can cin >> miles.Miles that, to me, is similar to a way of inputting into a structure. Right???

So a class is just like a struct???????

They're almost identical. They are far more alike than they are different.

Ok. I'm going to college now and I am studying computer programming. Game and simulation programming to be exact. I am only in programming 2 where we now go indepth in our coding. I have a problem with my code. can you help me out??? my thread is titled number guessing problem. Much gratitude will be given and much help will be appreciated.

This article has been dead for over six months. Start a new discussion instead.