Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please write a c++ code with proper use of variable constants for my pseudo code

ID: 3706616 • Letter: P

Question

Please write a c++ code with proper use of variable constants for my pseudo code. I am take a class that is teaching me flow charts and pseudocode and I would like to see the actual code so that I can start preparing myself for next semester’s classes. Here is the pseudo code:

// main module

Module main()

// Local variables

Declare InputFile salesFile

      Declare Integer count = 0, readNumber, lastNumber

      Declare Real readAmount, personTotal = 0, allTotal = 0

// open file

Open salesFile “brewster.dat”

// print headings

Display “Brewster’s Used Cars, Inc.”

Display “sales Report”

Display

Display “Salesperson ID          Sale Amount”

Display “===================================”

// read and display all sales in the file

While NOT eof(salesFile)

            Read salesFile readNumber readAmount

            Set count = count + 1

            // initialize

            If count == 1 Then

                  Set lastNumber = readNumber

            End If

            // check if sales ID changed

            If readNumber != lastNumber Then

                  Display “Total sales for this salesperson: “, personTotal

                  Display

                  Set personTotal = 0

                  Set lastNumber = readNumber

            End If

            // accumulate totals

            Set personTotal = personTotal + readAmount

            Set allTotal = allTotal + readAmount

      End While

      // closing totals

Display “Total sales for this salesperson: “, personTotal

      Display “Total of all sales: “, allTotal

// close the file

Close numbersFile

End Module

Output should look like this:

Use the provided 'brewster.dat' file to generate this output:

Explanation / Answer

#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <fstream>
#include <string>
using namespace std;

int main() {
    int count = 0;
    string a,b;
   int readAmount,readNumber,lastNumber,personTotal=0,allTotal=0;
    ifstream inFile;

    inFile.open("salesreport.txt");
    if (!inFile) {
        cout << "Unable to open file";
        return 0; // terminate with error
    }
   cout<<"============="<<endl;
   cout<<"Sales Report: "<<endl;
   cout<<"============="<<endl;
   cout<<"SalespersonID Sales Amount"<<endl;

    while(!inFile.eof())
     {

        inFile>>a>>b; //read name from file
        readNumber=atoi(a.c_str());
        readAmount=atoi(b.c_str());
        count++;


         if(count==1)
            {

         lastNumber=readNumber;

            }
        cout<<readNumber;
        cout<<" $"<<readAmount<<endl;

            if(readNumber!=lastNumber)

            {
                cout<<"Total sales for this person is :$"<<personTotal<<endl;
                personTotal=0;
                lastNumber=readNumber;
            }
            personTotal=personTotal+readAmount;
            allTotal=allTotal+readAmount;


    }
    cout<<"Total sales for this person is :$"<<personTotal<<endl;
cout<<"Total of all sales : $"<<allTotal<<endl;
    inFile.close();

    return 0;
}