If necessary, create a new project named Intermediate24 Project
and save it in the
Cpp8\Chap14 folder. Also create a new source file named
Intermediate24.cpp. If you
are using Microsoft Visual C++, copy the Intermediate24.txt file
from the Cpp8\Chap14
folder to the Cpp8\Chap14\Intermediate24 Project folder. Use a text
editor to open
the Intermediate24.txt file, which contains payroll codes and
salaries. Close the
Intermediate24.txt file. Create a program that allows the user to
enter a payroll
code. The program should search for the payroll code in the file
and then display the
appropriate salary. If the payroll code is not in the file, the
program should display an
appropriate message. The program should allow the user to display
as many salaries as
needed without having to run the program again. Save and then run
the program.
Test the program by entering the following payroll codes: 10, 24,
55, 32, and 6. Stop
the program.
Please use intermediate24.txt file =
1#23400
4#17000
5#21000
6#12600
9#26700
10#18900
11#18500
13#12000
15#49000
16#56500
20#65000
21#65500
22#78200
23#71000
24#71100
25#72000
30#83000
31#84000
32#90000
and finish using this code
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
int searchFor = 0;
int code = 0;
int salary = 0;
char found = 'N';
char another = 'Y';
ifstream inFile;
while (another == 'Y')
{
inFile.open("Intermediate24.txt",
ios::in);
if (inFile.is_open())
{
// enter the
needed logic here
// for entering
the payroll code
while
(!inFile.eof() && found == 'N')
{
// keep searching for the payroll code
// until EOF
} //end while
inFile.close();
if
(found == 'Y')
// if the code is found, do something...
else
cout << "Invalid payroll code"
<< endl <<
endl;
//end
if
found
= 'N';
cout <<
"Search for another code (Y or N)? ";
cin >>
another;
another =
toupper(another);
}
else
{
cout <<
"The Intermediate24.txt file could not be opened." <<
endl;
another =
'N';
} //end if
} //end while
return 0;
} //end of main function
The code is self explanatory and variables have been named appropriately.
Please refer to the screenshots for the indentation:
please comment before downvoting if any doubt, will resolve asap.
Code:
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
int searchFor = 0;
int code = 0;
int salary = 0;
char found = 'N';
char another = 'Y';
string payroll_code;
ifstream inFile;
while (another == 'Y')
{
inFile.open("Intermediate24.txt", ios::in);
if (inFile.is_open())
{
cout << "Enter the Payroll Code : "; // logic for getting the payroll code
cin >> payroll_code ;
cout << endl;
string line;
while (!inFile.eof() && found == 'N')
{
getline(inFile,line);
for(int i = 0; i < line.length(); i++)
{
if(line[i] == '#')
{
string cur_payroll = line.substr(0,i);
if(cur_payroll == payroll_code)
{
salary = stoi(line.substr(i+1));
found = 'Y';
break;
}
}
}
}
inFile.close();
if (found == 'Y') // if the code is found, print the salary
{
cout << "The salary for the given payroll is : " << salary << endl;
}
else
cout << "Invalid payroll code"
<< endl << endl;
//end if
found = 'N';
cout << "Search for another code (Y or N)? ";
cin >> another;
another = toupper(another);
}
else
{
cout << "The Intermediate24.txt file could not be opened." << endl;
another = 'N';
} //end if
} //end while
return 0;
} //end of main function
Screenshots:
Code:
Sample run:
If necessary, create a new project named Intermediate24 Project and save it in the Cpp8\Chap14 folder....
If necessary, create a new project named Intermediate23 Project and save it in the Cpp8\Chap12 folder. Also create a new source file named Intermediate23.cpp. Declare a seven-row, two-column int array named temperatures. The program should prompt the user to enter the highest and lowest temperatures for seven days. Store the highest temperatures in the first column in the array. Store the lowest temperatures in the second column. The program should display the average high temperature and the average temperature. Display...
What am I doing wrong here...…. Question is this : In this exercise, you will create a program that displays a table consisting of four rows and three columns. The first column should contain the numbers 10 through 13. The second and third columns should contain the results of squaring and cubing, respec- tively, the numbers 10 through 13. The table will look similar to the one shown in Figure 9-38. If necessary, create a new project named Introductoryl6 Project,...
In this exercise, you will modify the hypotenuse program shown earlier in Figure 9-6. Follow the instructions for starting C++ and viewing the ModifyThis13.cpp file, which is contained in either the Cpp8/Chap09/ModifyThis13 Project folder or the Cpp8/Chap09 folder. Remove both calculation tasks from the main function, and assign both to a program-defined value-returning function named getHypotenuse. Test the program appropriately. //Hypotenuse.cpp - displays the length of a right //triangle's hypotenuse #include <iostream> #include <iomanip> #include <cmath> using namespace std; int...
chapter 7. Create a program that allows the user to enter the ages (in years) of five people. The program should display the average age. Use the for the statement. Display the average age with one decimal place. If necessary, create a new project named TryThis15 Project, and save it in the Cpp8\Chap07 folder. Enter the C++ instructions into a source file named TryThis15.cpp. Also, enter appropriate comments and any additional instructions required by the compiler. Test the program using...
Follow the instructions for starting C++ and viewing the Intermediate23.cpp file, which is contained in either the Cpp8IChap11\Intermediate23 Project folder or the Cpp8\Chap11 folder. (Depending on your C++ development tool, you may need to open the project/solution file first.) The program uses an array to store the amount of money a game show contestant won in each of five days. The program should display the total amount won and the average daily amount won. It should also display the day...
Create a folder named "TrainerApp". In that folder create the following files. Create a PHP file, "insert-user-form.php", with a form that has the following fields: - First Name (text) - Last Name (text) - Email (text) - Password (text) - Submit button Create another PHP file, "insert-exercise-form.php" with a form that has the following fields: - Exercise Name (text) - Description (text) - Demonstration Image (file) - Submit button Create another PHP file, "login-user-form.php" with a form that has the...
Retrieve program randomAccess.cpp and the data file proverb.txt from the Lab 14 folder. The code is as follows: #include <iostream> #include <fstream> #include <cctype> using namespace std; 327 int main() { fstream inFile("proverb.txt", ios::in); long offset; char ch; char more; do { // Fill in the code to write to the screen // the current read position (with label) cout << "Enter an offset from the current read position: "; cin >> offset; // Fill in the code to move...
I need help solving this assignment, you are given a full piece of code that does not run correctly. Some of the bugs can be found at compile time, while others are found at run time. Access the UserMenu.cpp code file (in the zip file in Start Here) and use debugging practices and the debugger in Visual Studio to find each bug. Fix the bug and write a comment in the code giving a description of how you found the...
nothing happens when I replace the skeleton code. the program runs but it does not give me the desired results. All the question marks must be removed and filled in with the appropriate code.// Function prototypesvoid displayAllLines(ifstream &infile);void displayLastLine(ifstream &infile);int main(){// Arrays for file nameschar fileName1[SIZE];char fileName2[SIZE];// File stream objectsifstream jokeFile;ifstream punchlineFile;// Explain the program to the user.cout << "This program will print a joke "<< "and its punch line.\n\n";// Get the joke file name.cout << "Enter the name of...
I am having trouble figuring out what should go in the place of "number" to make the loop stop as soon as they enter the value they put in for the "count" input. I am also having trouble nesting a do while loop into the original while loop (if that is even what I am supposed to do to get the program to keep going if the user wants to enter more numbers???) I have inserted the question below, as...