Question

Write a program that does the following in C++ 1 ) Write the following store data...

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

Homework Answers

Answer #1

#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;
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
C++ Part B: (String) Program Description: Write a word search program that searches an input data...
C++ Part B: (String) Program Description: Write a word search program that searches an input data file for a word specified by the user. The program should display the number of times the word appears in the input data file. In addition, the program should count and display the number of grammatical characters in the input data file. Your program must do this by providing the following functions : void processFile(ifstream &inFile, string wordSearch, int &wordCount, int &grammaticalCount) ; (15%)...
C Program Write a program to count the frequency of each alphabet letter (A-Z a-z, total...
C Program Write a program to count the frequency of each alphabet letter (A-Z a-z, total 52 case sensitive) and five special characters (‘.’, ‘,’, ‘:’, ‘;’ and ‘!’) in all the .txt files under a given directory. The program should include a header count.h, alphabetcount.c to count the frequency of alphabet letters; and specialcharcount.c to count the frequency of special characters. Please only add code to where it says //ADDCODEHERE and keep function names the same. I have also...
You will write a program that loops until the user selects 0 to exit. In the...
You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an...
Write a C++ program which consists of several functions besides the main() function. 1)   The main()...
Write a C++ program which consists of several functions besides the main() function. 1)   The main() function, which shall ask for input from the user (ProcessCommand() does this) to compute the following: SumProductDifference and Power. There should be a well designed user interface. 2)   A void function called SumProductDifference(int, int, int&, int&, int&), that computes the sum, product, and difference of it two input arguments, and passes the sum, product, and difference by-reference. 3)   A value-returning function called Power(int a,...
Please do it in Python Write the simplest program that will demonstrate iteration vs recursion using...
Please do it in Python Write the simplest program that will demonstrate iteration vs recursion using the following guidelines - Write two primary helper functions - one iterative (IsArrayPrimeIter) and one recursive (IsArrayPrimeRecur) - each of which Take the array and its size as input params and return a bool. Print out a message "Entering <function_name>" as the first statement of each function. Perform the code to test whether every element of the array is a Prime number. Print out...
c++ Program Description You are going to write a computer program/prototype to process mail packages that...
c++ Program Description You are going to write a computer program/prototype to process mail packages that are sent to different cities. For each destination city, a destination object is set up with the name of the city, the count of packages to the city and the total weight of all the packages. The destination object is updated periodically when new packages are collected. You will maintain a list of destination objects and use commands to process data in the list....
Consider the C program (twoupdate) to demonstrate race condition. In this assignment, we will implement Peterson's...
Consider the C program (twoupdate) to demonstrate race condition. In this assignment, we will implement Peterson's algorithm to ensure mutual exclusion in the respective critical sections of the two processes, and thereby eliminate the race condition. In order to implement Peterson's Algorithm, the two processes should share a boolean array calledflagwith two components and an integer variable called turn, all initialized suitably. We will create and access these shared variables using UNIX system calls relating to shared memory – shmget,...
This program is in C++: Write a program to allow the user to: 1. Create two...
This program is in C++: Write a program to allow the user to: 1. Create two classes. Employee and Departments. The Department class will have: DepartmentID, Departmentname, DepartmentHeadName. The Employee class will have employeeID, emploeename, employeesalary, employeeage, employeeDepartmentID. Both of the above classes should have appropriate constructors, accessor methods. 2. Create two arrays . One for Employee with the size 5 and another one for Department with the size 3. Your program should display a menu for the user to...
ALL CODE MUST BE IN C++ Before you begin, you must write yourself a LinkedList class...
ALL CODE MUST BE IN C++ Before you begin, you must write yourself a LinkedList class and a Node class (please name your classes exactly ​as I did here). Please follow the below specifications for the two classes. Node.cpp ● This must be a generic class. ● Should contain a generic member variable that holds the nodes value. ● Should contain a next and prev Node* as denoted here. ● All member variables should be private. ● Use public and...
You are to write a C++ program to produce an inventory report for a local company....
You are to write a C++ program to produce an inventory report for a local company. Your input will be item name, item number, quantity, price per item, safe stock value. The following shows which columns the input will be in: item name             item number         quantity                  price                      safe stock 20 chars                 5 char                     3 char                      6 chars                 3 chars Output will be as follows: item number         item name    quantity   price     price*quantity   %ofStock    flag You will put a symbol in the...