Creating a class

May 6, 2013 at 5:31am

Trying to create a class,
im new to programming and have been watching some videos on youtube
but still not quite sure how to go about this.

Some guidance to point me in the right direction would be much appreciated.

This is the assigment,
*******
Create a class that represents gas and diesel prices at a gas station. Attributes are the cost per gallon of regular, mid-grade, and premium gasoline, and the cost per gallon for diesel fuel. The class must contain the following methods/functions:

1) Default constructor with all attributes set to 0

2) Initial value constructor

3) Accessors for all attributes

4) Mutators for all attributes

5) An average cost function that returns the average cost per gallon.

6) Functions that return the total cost for a given amount of gallons. Inputs are the type of fuel (1 = regular, 2 = mid-grade, 3 = premium, 4 = diesel) and the number of gallons
*******

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#pragma once
class Station
{

	int regular,midgrade,premium,diesel;

public:
	Station(void);
	~Station(void);

	int getRegular();
	void setRegular(int);
	int getMidgrade();
	void setMidgrade(int);
	int getPremium();
	void setPremium(int);
	int getDiesel();
	void setDiesel(int);

};

THIS IS WHATS IN MY .H FILE
Last edited on May 6, 2013 at 5:46am
May 6, 2013 at 5:34am

When they refer to attributes, would this go in the .H file along
with the int price??? then set it all equal to zero, [ ie. int price(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
#include "Station.h"
#include <iostream>

using namespace std;


Station::Station(void)
{
	cout << "Creating a class" << endl;
}


Station::~Station(void)
{
}

int Station::getRegular()
{
	return regular;
}

void Station::setRegular (int mRegular)
{
	regular = mRegular;
}

int Station::getMidgrade()
{
	return midgrade;
}

void Station::setMidgrade (int mMidgrade)
{
	midgrade = mMidgrade;
}

int Station::getPremium()
{
	return premium;
}

void Station::setPremium (int mPremium)
{
	premium = mPremium;
}

int Station::getDiesel()
{
	return diesel;
}

void Station::setDiesel (int mDiesel)
{
	diesel = mDiesel;
}
THIS IS WHAT IN MY .CPP FILE
Last edited on May 6, 2013 at 5:47am
Topic archived. No new replies allowed.