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.
#include<iostream>
#include<cstdlib>
#include<cctype>
usingnamespace 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;
}
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!
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.
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!
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.
#include<iostream>
#include<cstdlib>
#include<cctype>
usingnamespace 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" ;
}elseif ( cost < revenue){
loss = revenue - cost;
cout<< "loss";
} elseif (cost == revenue){
cout<< "no profit or loss";
}
return 0;
}