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

2) Start Raptor, and create a Raptor program as follows. The program will ask th

ID: 3759406 • Letter: 2

Question

2) Start Raptor, and create a Raptor program as follows. The program will ask the user for a number of days (which becomes the loop control variable), opens an output file, prompts the user for sales amounts and writes them to the file. Then it closes the file and reopens it for input, reads the numbers from the file and displays them. a. Right-click the Start symbol and select Comment. Type comment lines for the Author, Date, and Description, then click Done. Do this for all Raptor programs. b. Call a built-in Raptor function named Clear_Console c. Prompt the user for the number of days (line 14 on page 390), and store the result in numDays d. Initialize the variable counter to 1. e. Open a file for output by calling the Raptor function Redirect_Output(“sales.dat”). The file will be created in the same folder as your Raptor files. f. Create a loop with the exit condition counter > numDays. Inside the loop: i. Prompt the user to enter sales for the day indicated by counter (line 24 on page 390), and store the input in sales ii. Use an Output symbol to write the sales amount to the file (you have already redirected the output to the file). iii. Add 1 to counter g. Outside the loop (the YES branch), close the output file by calling Redirect_Output(no) h. Then open the file for input by calling Redirect_Input(“sales.dat”) i. Display the message “Here are the sales amounts:” j. Format your output to 2 decimal places by calling a built-in Raptor function called Set_Precision(2). k. Reset the counter to 1, and create a new loop with the exit condition End_Of_Input. l. Inside the loop use an Input symbol to read the sales amount from the file. Use the prompt “Read number:” (The prompt will not actually appear anywhere, since input is coming from the file.) m. Use an Output symbol to display the amount in the Master Console with a “$” + sales. n. Add 1 to counter o. Run the program with the input on page 390. Your output in the Master Console should show the same output as at the bottom of page 392, although the amounts will not have commas. See the screen shot below. p. If there are any errors, recheck the instructions and correct them, then resave the file.

Explanation / Answer

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

int main()
{
ofstream outputFile;
string name;
int number;

//set format for dollar values
cout << fixed << showpoint << setprecision(2);
//Get user to open their file
do
{
cout << "To enter sales for Reid, enter R. "
<< "To enter sales for Jarid, enter J. "
<< "To enter sales for Nicole, enter N. "
<< "Enter your choice: ";
cin >> name;
// input validation for name
while (!(name == "R" || name == "J" || name == "N"))
{
cout << "Enter the first letter of your first name in caps: ";
cin >> name;
}

if (outputFile)
{
name += ".txt";
outputFile.open(name.c_str());
int sales;
double total = 0.0;

cout << "How many sales ammounts will you enter (Maximum is 4): ";
cin >> sales;
// input validation number of sales entered
if ((sales <= 0) || (sales >= 5))
{
cout << "Number is invalid may not be less than 1 or more "
<< "than 4. "
<< "Enter ammount of sales to be entered: ";
cin >> sales;
}
for (int count = 1; count <= sales; count++)
{
double ammount;
cout << "Enter the ammount for sale " << count << ": ";
cin >> ammount;
// Store total
total += ammount; //accumulate running total

double commission = total * .1;
outputFile << commission << endl;
outputFile << total << endl;

cout << "Commission earned for sales entered is: " << commission << endl;

// close file
outputFile.close();
}
}
cout << "Enter Z to quit or any key to go to menu: ";
cin >> name;
} while (name != "Z");


// display sales table

ifstream inputFile;

double total;
double commission;

inputFile.open("R.txt");

inputFile >> commission;
cout << "Total commission earned for Reid is: " << commission << endl;

inputFile.close();

inputFile.open("J.txt");
inputFile >> commission;
cout << "Total commission earned for Jarid is: " << commission << endl;
inputFile.close();

inputFile.open("N.txt");
inputFile >> commission;
cout << "Total commission earned for Nicole is: " << commission << endl;
inputFile.close();


system ("pause");
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote