Javed Iqbal. Roll.208 Labno5 Task No 1: // Fig. 14.6: Fig14 - 06.cpp // Reading and Printing A Sequential File
Javed Iqbal. Roll.208 Labno5 Task No 1: // Fig. 14.6: Fig14 - 06.cpp // Reading and Printing A Sequential File
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
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. }