please help me

1-Includes a function “Display” to display the field values for each order that the item_price is greater than JD 100.
2-Includes a function “Search” to display the field values for each order that the customer name is “Ali”.
3-Write a main() function that contains an array of five Order objects and store appropriate data in it. Then, continue to prompt the user for Order data. Your program must calculate the total prices of the five orders.
4-Overloads an operator+() function to calculate the total price. In this function, you need to sum the prices of five orders.
5-Overloads an operator<() function to find the lowest order price of five orders.

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
  #include<iostream>
#include<string>
using namespace std;
class Order {
private:
	string Customer_name;
	double Customer_number;
	string Item;
	double Quantity;
	double Unit_price;
	double Item_price;
public:
	 Order(string c_name, double c_num, string item, double quant, double u_price, double i_price) {
		
		 Customer_name = c_name;
		 Customer_number = c_num;
		 Item = item;
		 Quantity = quant;
		 Unit_price = u_price;
		 Item_price = i_price;
	}//constructor
	 Order() {

	 }//empty constructor
	 int Compute () 
	 {
		 double result = Quantity * Unit_price;
		 return result;
	 }
	 void display() {
		 cout << "The Customer Name is: " << Customer_name << endl;
		 cout << "The Customer Number is: " << Customer_number << endl;
		 cout << "The Item is: " << Item << endl;
		 cout << "The Quantity is: " << Quantity << endl;
		 cout << "The Unit price is: " << Unit_price << endl;
		 cout << "The Item price is: " << Item_price << endl;

	 }
};
void main() 
{

}
Hello abuh,

You have a nice start on your class.You have covered #1, but #2 is missing.#3is started, but lacking.And 4 and 5 are missing.You do not need a "cout" and "endl" for every line and prefer to use the new line, (\n), over the function "endl".You could write the "display" function as:
1
2
3
4
5
6
7
    cout <<
        "The Customer Name is: " << Customer_name << "\n"
        "The Customer Number is: " << Customer_number << "\n"
        "The Item is: " << Item << "\n"
        "The Quantity is: " << Quantity << "\n"
        "The Unit price is: " << Unit_price << "\n"
        "The Item price is: " << Item_price << '\n';

Using the insertation operator, (<<), you can chain as much as you need into 1 "cout" statement. And the end of line 2 and the beginning of line 3 are considered 1 string. Whether you write it this way or put the(\n) at the beginning of line 3 is up to you.Either way works.
Your "compute" function could simply return Quantity * Unit_price;.There is no need for the extra work.

Andy
Hello abuh,

When I went to compile the program the compiler complained about: void main(). This is an old C style. Modern C++ requires int main().

Andy
Hello abuh,

Since I am not in your class I have a question.

In #3 it says
Then, continue to prompt the user for Order data.

Does this need to be done as a class function or something else?

Andy
Customer number as a double??

When passing string as a function parameter, pass as a ref rather than by value to avoid an copy (unless a copy is required).

For a constructor, initialise variables rather than assignment

Compute should return double and not int

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

class Order {
	string Customer_name;
	double Customer_number {};
	string Item;
	double Quantity {};
	double Unit_price {};
	double Item_price {};

public:
	Order(const string& c_name, double c_num, const string& item, double quant, double u_price, double i_price) :
		Customer_name(c_name), Customer_number(c_num), Item(item), Quantity(quant), Unit_price(u_price), Item_price(i_price) {}

	Order() {} //empty constructor

	double Compute() const { return Quantity * Unit_price; }

	void display() {
		cout << "The Customer Name is: " << Customer_name << '\n';
		cout << "The Customer Number is: " << Customer_number << '\n';
		cout << "The Item is: " << Item << '\n';
		cout << "The Quantity is: " << Quantity << '\n';
		cout << "The Unit price is: " << Unit_price << '\n';
		cout << "The Item price is: " << Item_price << '\n';
	}
};

void main()
{

}

Topic archived. No new replies allowed.