Write a program that does the following in C++
1 ) Write the following store data to a file (should be in main)
DC Tourism
Expenses 100.20
Revenue 200.50
Maryland Tourism
Expenses 150.33
Revenue 210.33
Virginia Tourism
Expenses 140.00
Revenue 230.00
2 ) Print the following heading: (should be in heading function)
Store name | Profit
[Note: use setw to make sure all your columns line up properly]
3 ) Read the store data for one store (should be in main)
4 ) Calculate the profit for the store (should be in getProfit function)
5 ) Print the store information in the following format (should be in printMessage function)
|
[Note: use setw to make sure all your columns line up properly]
6 ) Repeat steps 4-5 in an end of file loop [should be in main]
Your answer should look like this:
Store name Profit
DC Tourism 100.30
Maryland Tourism 60.00
Virginia Tourism 90.00
Functions you need
Function name | Parameters | Return Type
heading | N/A | void
getProfit | expenses,revenue | float
PrintMessage | storeName1, profit | void
#include <iostream>
#include<string>
#include<iomanip>
using namespace std;
float getProfit(float expenses, float revenue)
{
return
revenue-expenses; //
Return Profit
}
void printMessage(int n,string name_of_company[],float expenses[],
float revenue[])
{
for(int i = 0;i < n;i++)
{
cout<<setw(10)<<name_of_company[i]<<"\t"<<getProfit(expenses[i],revenue[i])<<endl;
}
}
int main()
{
int n;
string name_of_company[100];
float expenses[100],revenue[100];
cout<<"\n Enter total number of
Company "; // Total company
cin>>n;
for(int i = 0; i<n ;i++)
{
string name;
cout<<" Enter
Name of Company: ";
getline(cin,
name);
getline(cin,
name); //
Name of company
name_of_company[i]
= name;
cout<<"\n
Enter expenses of
"<<name_of_company[i];
cin>>expenses[i]; //
Expenses of Company
cout<<"\n
Enter revenue of "<<name_of_company[i];
cin>>revenue[i]; //
Revenue of Company
}
cout<<setw(10);
cout<<"\n Store name | Profit\n";
printMessage(n,name_of_company,expenses,revenue); // Print Company Data
return 0;
}
Get Answers For Free
Most questions answered within 1 hours.