Assignment help with OOD

I am having a ton of trouble with understanding classes and objects, and i don't know why i just can't get this assignment to make sense to me. I've re written it a few times and I'm getting kind of frustrated.

Create a class named Order that performs order processing of a single item. The class has the following five fields:

Customer name
Customer number
Quantity ordered
Unit price
Total price

Include set and get methods for each field except the total price field. The set methods prompt the user for values for each field. This class also needs a method to compute the total price (quantity times unit price) and a method to display the field values.

Create a subclass named ShippedOrder that overrides computePrice() by adding a shipping and handling charge of $4.00. Write an application named UseOrder that instantiates an object of each of these classes. Prompt the user for data for the Order object, and display the results, then prompt the user for data for the ShippedOrder object, and display the results.

I realize that what I have here probably looks like garbage, since I've been bombing through the textbook trying to figure out what I'm doing wrong. I can't figure out how to get anything in int main() to talk to the classes. Thanks in advance for any help you can give me.

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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#include <iostream>
#include <string>

using namespace std;

class Order // Class order and its attributes
{
public:
	int getNum(int ID) const;
	int getQuant(int quantity) const;
	double getPrice(double price) const;
	double calcTotal();
	void setName(string first, string last);
	void print() const;
	void setInfo(string first, string last, int ID, int quantity, double price);
	void setTotal(double p, int q);
	string getFirst() const;
	string getLast() const;
	string fname;
	string lname;
private:
	double price;
	int quantity;
	int ID;
	
};

void Order::setName(string first, string last)
{
	fname = first;
	lname = last;
}
void Order::setInfo(string first, string last, int ID, int quantity, double price)
{
	cout << "Enter your First name: "<<endl;
	cin>> first;
	cout << "Enter your last name: "<<endl;
	cin >> last;
	cout<< "Enter your Order quantity: "<<endl;
	cin >> quantity;
	cout << "Enter the price per unit: "<<endl;
	cin>> price;
}

string Order::getFirst() const
{
return fname;
}
string Order::getLast() const
{
return lname; 
}
int Order::getNum(int ID) const
{
	return ID;
}
int Order::getQuant(int quantity) const
{
	return quantity;
}
double Order::getPrice(double price) const
{
	return price;
}
void Order::setTotal(double p, int q)
{
	if (p >= 0)
		price=p;
	else(price=0);
	if(q >= 0)
		quantity = q;
	else quantity = 0;
}
double Order::calcTotal() // calcultate total
{
	return price * quantity;
}
void Order::print() const
{
	cout<< " Customer Name is: " << fname << " " << lname << endl;
	cout<< "Member ID is: " << ID <<endl;
	cout<< "Your Order quantity is: " << quantity << endl;
	cout<< "The price per unit is: " << price << endl;
	cout<< "The total amount due is: " << price * quantity << endl;
}


// Shipping subclass

class ShippedOrder: public Order
{
public:
	void GetShip();
	void Shipping();
	double shipped;
	double free;
	void Total(int ShipPrice);
private:
	int shipChoice;
	double ShipPrice;
};


void ShippedOrder::GetShip()
{

	cout<< "Do you wish to have the product shipped to you for an additional 4.00?\n"
		<< "(Enter y for yes or n for no)"<<endl;
	cin >> shipChoice;
	switch (shipChoice)
	{
		case 'y':
			ShipPrice = 4.00;
			break;
		case 'n':
			ShipPrice = 0.00;
		default:
			cout<< "please enter a (y) or (n)"<<endl;
	}
}
int main()
{
	Order package;

	package.setInfo();




Last edited on
. The class has the following five fields:

Customer name
Customer number
Quantity ordered
Unit price
Total price

Include set and get methods for each field except the total price field.

You're going to want five data members within the class: name(string), number(int), quantity(int), price(int/double?), total(int/double?). You're going to want them to be private members because the assignment calls for them to have get/set functions which will modify and call the variables themselves, so you'll never need public access to them.

Speaking of functions, you'll need ten.

Include set and get methods for each field except the total price field. The set methods prompt the user for values for each field. This class also needs a method to compute the total price (quantity times unit price) and a method to display the field values.

setName, getName. setNumber, getNumber, setQuanity, getQuanity, setPrice, getPrice, calculateTotalPrice, printOrder. Remember that the get function do not need parameters. They are just going to return a value from the class. All of these functions will be public.

This should get you started for now. :P I'd recommend getting the skeleton of your class set up first before you begin writing any functions. Just declare variables and write prototypes.
Last edited on
Thanks Keene, that was extremely helpful. It cleared up a lot of confusion I had about set and get. I'm almost done with yet another rewrite of the program. Hopefully it works this time around.
So i still cant seem to get this program to work. Any additional advice would be greatly appreciated.
Here is my updated code.

This is the header file
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <iostream>
#include <string>

using namespace std;

class Order // Class order and its attributes
{
public:
	void setName(string myName);
	string getName();
	void setNumber(int ID);
	int getNumber();
	void setQuanity(int Quant);
	int getQuanity();
	void setPrice(double money);
	double getPrice();
	double calculateTotalPrice();
	void printOrder();
	double ship;
	void SetShip(int yes);
private:
	string name;
	int number;
	int quantity;
	double price;
	double total;
};
string Order::getName()
{
	return name;
}
int Order::getNumber()
{
	return number;
}
double Order::getPrice()
{
	return price;
}
int Order::getQuanity()
{
	return quantity;
}
double Order::calculateTotalPrice()
{
	return price * quantity + ship;
}
void Order::setName(string myName)
{
	myName = name;
}
void Order::setNumber(int ID)
{
	ID = number;
}
void Order::setQuanity(int Quant)
{
	Quant = quantity;
}
void Order::setPrice(double money)
{
	money = price;
}

class ShippedOrder: public Order //Subclass of ShippedOrder
{
public:
	void SetShip(int yes);
private:
	double shipping;
};

void Order::SetShip(int yes)
{
	cin >> yes;
	switch (yes)
	{
		case 'y':
			Order.ship = 4.00;
			break;
		case 'n':
			Order.ship = 0.00;
		default:
			cout<< "please enter a (y) or (n)"<<endl;
	}

And this is the main file.

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
#include <iostream>
#include <string>
#include "Order.h"
using namespace std;

	int main()
{
	string yourName;
	int yourNumber;
	int yourQuantity;
	double yourPrice;
	int Yes;

	Order homework;
	
	cout<< "Enter your First and last name: "<<endl;
	cin>> yourName;
	homework.setName(yourName);
	cout<< "Enter your member ID number: "<<endl;
	cin>> yourNumber;
	homework.setNumber(yourNumber);
	cout<< "Enter the quantity bought: "<<endl;
	cin>> yourQuantity;
	homework.setQuanity(yourQuantity);
	cout<< "Enter the price per unit: "<<endl;
	cin>> yourPrice;
	homework.setPrice(yourPrice);
	cout<< "Thank you! Your name is: " << yourName
		<< "\nYour ID number is: "<< yourNumber
		<< "\nThe amount purchased is: " <<yourQuantity
		<< "\nThe price per unit is: " << yourPrice
		<< "\nThe total amount due before shipping is: "<< yourQuantity * yourPrice<<endl;
	system("CLS");
	cout<< " Would you like to ship this product? "<<endl;
	cin >> Yes;
	homework.SetShip(Yes);


	




	system("pause");

	return 0;
}

The first thing I notice is that your set methods don't do anything; look at the assignment operations you perform.
Topic archived. No new replies allowed.