Payroll Amount Sequential Order Fixed Point Notation

If necessary, create a new project named Introductory19 Project. Also create a new source file named Introductory19.cpp. Create a program that saves a company’s payroll amounts in a sequential access file. Save the amounts in fixed-point notation with two decimal places. Name the sequential access file Introductory19.txt and open the file for append. Use a negative number as the sentinel value. Save and then run the program. Enter the following payroll amounts and sentinel value: 45678.99, 67000.56, and -1. Now, run the program again. This time, enter the following payroll amounts and sentinel value: 25000.89, 35600.55, and -1. Open the Introductory19.txt file in a text editor. The file should contain four payroll amounts, with each amount appearing on a separate line in the file. Close the Introductory19.txt file.
[code#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
using namespace std;


int main()
{
ofstream outPayroll;
outPayroll.open("Introductory19.txt", ios::app);
double payroll = 0.0;
//check if file was opened.
if (outPayroll.is_open())
{
cout << "Enter payroll amount (-1 to end): ";
cin >> payroll;
while (payroll != -1)
{
outPayroll << fixed << setprecision(2);
outPayroll << payroll << endl;
cout << "Enter another payroll amount"
<< "(-1 to end): ";
cin >> payroll,
} //end while
}
else
cout << "File could not be opened." << endl;
outPayroll.close();
return 0;
} // end of main function][/code]
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// If necessary, create a new project named Introductory19 Project. 
// Also create a new source file named Introductory19.cpp.
// Create a program that saves a company’s payroll amounts in a sequential 
// access file. Save the amounts in fixed-point notation with two decimal 
// places. Name the sequential access file Introductory19.txt and open the file 
// for append. Use a negative number as the sentinel value. Save and then run 
// the program. Enter the following payroll amounts and sentinel value: 
// 45678.99, 67000.56, and -1. Now, run the program again. This time, enter the 
// following payroll amounts and sentinel value: 25000.89, 35600.55, and -1. 
// Open the Introductory19.txt file in a text editor. The file should contain 
// four payroll amounts, with each amount appearing on a separate line in the 
// file. Close the Introductory19.txt file.
#include <iomanip>
#include <iostream>
#include <fstream>
#include <string>

void waitForEnter();

int main()
{
    std::ofstream outPayroll("Introductory19.txt", std::ios::app);
    //check if file was opened.
    if(!outPayroll.is_open()) {
        std::cout << "File could not be opened.\n";
        return 0;
    }

    std::cout << "Enter payroll amount (-1 to end): ";
    double payroll = 0.0;
    while(std::cin >> payroll && payroll != -1) {
        if(payroll != -1) {
            outPayroll << std::fixed << std::setprecision(2) << payroll << '\n';
        }
    }

    outPayroll.close();
    waitForEnter();
    return 0;
}

void waitForEnter()
{
    std::cout << "\nPress ENTER to continue...\n";
    std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
}

Last edited on
Topic archived. No new replies allowed.