May I ask what to do since, thanks!

This assignment is a C++ Program. The aim is calculate whether a company has profit or loss in a month. In order to achieve this aim, the followings are some tips provided for you all.

Try to create a class Called "TheCompany". This class should contain the followings:
1. An array to store the name of the company
2. A variable to store the cost per product created
3. A variable to store the number of products created
4. A variable to store the price of each product sold
5. A variable to store the number of products sold

In the main() function, you should ask the user what's the name of his/her company.
Then, fill in the above variables by asking the users.

Remember that the number of products sold should not more than the number of products created. If that happens, prompt the users to enter the data again until this requirement is met.

Also, here are some equations for you:
1. Total cost = cost per product * number of products created
2. Total revenue = price per product * number of products sold
3. Total Profit/Loss = Total cost - Total revenue

Bear in mind that in the case of loss, you should take an absolute value on the result.

When the above things are done, print out the company name and tell the user how much his/her company gets in profit/loss.
Last edited on
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
#include<iostream>
#include<cstdlib>
#include<cctype>
using namespace std;

class TheCompany{
public:
char CompanyName [100]; //Allows for a company name of up to 100 characters long 
int Cost_perproduct; //store the cost per product
int Num_products; //store the number of products created
int Pri_eachproduct; //store the price of each product sold
int Num_prodcutsold; //store the number of products sold

};

int main(){
cout<<"Please enter the name of company."<<endl;
cin>> CompanyName;
cout<<"Please enter the cost per product created."<<endl;
cin>> Cost_perproduct;
cout<<"Please enter the number of products created."<<endl;
cin>> Num_products;
cout<<"Please enter the price of each product sold."<<endl;
cin>> Pri_eachproduct;
cout<<"Please enter number of products sold."<<endl;
cin>> Num_prodcutsold;
return 0;
}
Last edited on
You forgot a semicolon after your class definition.
You forgot a semicolon after your class definition. <----Can you provide the correct definition? Thanks!
};
rofl - the question was 50x longer than the answer
Last edited on
Also, if the
chi wrote:
assignment is a C Program
then you must know that there is no such thing as a class in C. There is a struct, though.
http://en.wikipedia.org/wiki/Struct_(C_programming_language)
Last edited on
Good point - some confusion in the OP
I see you edited your code. But you still haven't confirmed if this is C or C++.
re:L B
Also, if thechi wrote:
assignment is a C Program
then you must know that there is no such thing as a class in C. There is a struct, though.
http://en.wikipedia.org/wiki/Struct_(C_programming_language)

it's helpful, thanks, master:)

re:kfmfe04

i am confuse on C++OOP... sad
Will test next Monday, and I still do not understand C + + OOP.

re:L B
It's a c++ assignment, thanks for your help!
Last edited on
OK, so it looks like you have it handled. If you need help you can keep posting here ;)

Note: nameofthecompany is just one char. I think you meant to make it a char array as the instructions say.
Last edited on
Can you provide a sample on it for me?
Thanks!
char CompanyName [100]; //Allows for a company name of up to 100 characters long
Can you provide a complete answer to me? Although I think this is very excessive, should be their own homework to complete, but I really no way to write from.
Last edited on
Unfortunately, we do not provide complete solutions for virtually any reason. Sorry. We will happily however help you out with any code you wrote!

-Albatross
Albatross (1549) Sep 26, 2010 at 1:45pm
Unfortunately, we do not provide complete solutions for virtually any reason. Sorry. We will happily however help you out with any code you wrote!


Well, i try it T.T
If I am wrong, please advice.
closed account (3TkL1hU5)
I wrote the program up myself as per your instructions.

I'm sorry but I will not be posting the final result. But I am having some trouble with the calculation in my program. It always outputs the profit / loss in the form of X.XXe+XXX.

EDIT:

I just realized it's outputting the same number every time no matter what the input is.

/confused

reEDIT: Figured it out. :D Works like a charm.
Last edited on
I have got it!!
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
#include<iostream>
#include<cstdlib>
#include<cctype>

using namespace std;

class TheCompany{
public:
char CompanyName [100]; //Allows for a company name of up to 100 characters long 
double Cost_perproduct; //store the cost per product
int Num_products; //store the number of products created
double Pri_eachproduct; //store the price of each product sold
int Num_prodcutsold; //store the number of products sold
};

int main()
{

double revenue, loss, cost;

cost = revenue = loss = 0.0;
TheCompany.Num_products = TheCompany.Num_prodcutsold = 0;

cout<<"Please enter the name of company."<<endl;
cin>> TheCompany.CompanyName;
cout<<"Please enter the cost per product created."<<endl;
cin>> TheCompany.Cost_perproduct;

do{
if (TheCompany.Num_prodcutsold > TheCompany.Num_products){
cout<<"\nThe number of products sold should not be more than number of products." <<endl;
} 
cout<<"Please enter the number of products created."<<endl;
cin>> TheCompany.Num_products;

if (TheCompany.Pri_eachproduct == 0){
cout<<"Please enter the price of each product sold."<<endl;
cin>> TheCompany.Pri_eachproduct;
}

cout<<"Please enter number of products sold."<<endl;
cin>> TheCompany.Num_prodcutsold;

}while(TheCompany.Num_prodcutsold >= TheCompany.Num_products);

cost = TheCompany.Cost_perproduct * TheCompany.Num_products;
revenue = TheCompany.Pri_eachproduct * TheCompany.Num_prodcutsold;


cout<< "\n\n" << TheCompany.CompanyName<<"\n";
if ( cost >= revenue){
loss = cost - revenue;
cout<<"profit" ;
}else if ( cost < revenue){
loss = revenue - cost;
cout<< "loss";
} else if (cost == revenue){
cout<< "no profit or loss";
}


return 0;
}
Last edited on
Congratualtions!
L B (327) Sep 28, 2010 at 8:19pm
Congratualtions!

Thanks!!!
Topic archived. No new replies allowed.