0% found this document useful (0 votes)
29 views

Javed Iqbal. Roll.208 Labno5 Task No 1: // Fig. 14.6: Fig14 - 06.cpp // Reading and Printing A Sequential File

This document contains code for two tasks. The first task reads data from a file called "clients.txt" containing account, name, and balance information and outputs it in a formatted table. The second task defines a payroll struct containing employee data like name, number, hours, pay rate, and gross pay. It prompts the user to input an employee's information and then outputs the data in a formatted manner.

Uploaded by

Mariyam khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

Javed Iqbal. Roll.208 Labno5 Task No 1: // Fig. 14.6: Fig14 - 06.cpp // Reading and Printing A Sequential File

This document contains code for two tasks. The first task reads data from a file called "clients.txt" containing account, name, and balance information and outputs it in a formatted table. The second task defines a payroll struct containing employee data like name, number, hours, pay rate, and gross pay. It prompts the user to input an employee's information and then outputs the data in a formatted manner.

Uploaded by

Mariyam khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Javed iqbal. Roll.

208

LAB NO 5
TASK NO 1
1. // Fig. 14.6: Fig14_06.cpp
2. // Reading and printing a sequential file.
3. #include <iostream>
4. #include <fstream>
5. #include <iomanip> 6. #include <string>
7. #include <cstdlib> 8. using
namespace std;
9.
10. void outputLine(int, const string&, double); // prototype
11.
12. int main()
13. {
14. //
15. ifstream inClientFile("clients.txt", ios::in);
16.
17.
18. if ( !inClientFile )
19. {
20. cerr << "File could not be opened" << endl;
21. exit(EXIT_FAILURE);
22. } // end if
23.
24. int account; // the account number
25. string name; // the account owner's name
26. double balance; // the account balance
27.
28. cout << left << setw(10) << "Account" << setw(13) 29. << "Name" <<
"Balance" << endl << fixed << showpoint;
30.
31. // display each record in file
32. while ( inClientFile >> account >> name >> balance )
33. outputLine(account, name, balance);
34. } // end main

35. // display single record from file


36. void outputLine(int account, const string & name, double balance)
37. {
38. cout << left << setw(10) << account << setw(13) << name
39. << setw(7) << setprecision(2) << right << balance << endl;
40. } // end function outputLine

LAB NO 5
TASK NO 2
1. //
2. #include <iostream>
3. #include <string>
4. #include <iomanip> 5. using namespace std;
6.
7. struct payRoll
8. {
9. int empNumber;
10. string name;
11. double hours;
12. double payRate; 13. double grossPay;
14.
15. };
16. int main()
17. {
18. payRoll employee;
19.
20. //
21. cout << "Enter the employee's number: ";
22. cin >> employee.empNumber;
23.
24. //
25. cout << "Enter the employee's name: ";
26. cin.ignore();
27. getline(cin, employee.name);
28.
29. //
30. cout << "How many hours did the employee work? ";
31. cin >> employee.hours;
32.
33. //
34. cout << "What is the employee's hourly payRate? ";
35. cin >> employee.payRate;
36.
37. //
38. employee.grossPay = employee.hours * employee.payRate;
39.
40. //
41. cout << "Here is the employee's payRoll data:\n"; 42. cout << "Name: " <<
employee.name << endl;
43. cout << "Number: " << employee.empNumber << endl;
44. cout << "Hours worked: " << employee.hours << endl;
45. cout << "Hourly payRate: " << employee.payRate << endl;
46. cout << fixed << showpoint << setprecision(2);
47. cout << "Gross pay: $" << employee.grossPay << endl;
48. return 0;
49. }

You might also like