Question
----it is not working on x code- #1 says 2 unused variables---- C++ ----------- T hese 3 questions were answered incorrectly in the expert q
----it is not working on x code- #1 says 2 unused variables---- C++ ----------- These 3 questions were answered incorrectly in the expert q qnd a- they had errors . please help if you are another expert out there. this should all be in c++
THIS IS THE CODE THEY GAVE ME BELOW
this code is incorrect
John Smith 10 15 Sarah Johnson 40 12 Mary Taylor 27 13 Jim Stewart 25 8
______________
#include
#include
#include
using namespace std;
//Function declaration
void readData(ifstream& dataIn,ofstream& dataOut);
int main() {
string fname,lname;
double workingHrs,hourlyRate;
//defines an input stream for the data file
ifstream dataIn;
//Defines an output stream for the data file
ofstream dataOut;
//Setting the precision
dataOut
//Opening the input file
dataIn.open("employees.txt");
//checking whether the file name is valid or not
if(dataIn.fail())
{
cout
return 1;
}
else
{
//creating and Opening the output file
dataOut.open("results.txt");
readData(dataIn,dataOut);
//Closing the intput file
dataIn.close();
//Closing the output file.
dataOut.close();
}
return 0;
}
//This function will read and process the data and write to outfile
void readData(ifstream& dataIn,ofstream& dataOut)
{
string fname,lname;
double workingHrs,hourlyRate;
while(dataIn>>fname>>lname>>workingHrs>>hourlyRate)
{
dataOut
}
}
QUESTION 2
THIS IS THE CODE THEY GAVE ME
this code is incorrect
#include #include #include
using namespace std;
int getData(int *arr) { cout > filename; ifstream in(filename.c_str()); int size = 0; if(in.is_open()) { int score; string temp; while(in >> temp >> temp >> score) { arr[size++] = score; } } else { cout
double avg(int *arr, int size) { double total = 0; for(int i = 0; i
int max(int *arr, int size) { int temp = arr[0]; for(int i = 0; i temp) { temp = arr[i]; } } return temp; }
int main() { int arr[1000]; int size = getData(arr); cout
QUESTION 3
THIS IS THE CODE THEY GAVE ME
incorrect code below
#include #include #include #include #include
void countchar(char *filename) { ifstream fin(filename); char ch; std::string line; int i,j,alpha=0,others=0,digi=0,lines=0; cout64&&i96&&i47&&i
} fin.clear(); fin.seekg (0, ios::beg); cout
cout
cout
}
int main() { char *filename="nameofyourfile.txt"; char a; countchar(filename); return 0; getch(); }
Question 1: Consider a text file named "employees.txt". The file contains data organized according to the following format: John Sarah Mary Jim Smith Johnson Taylor Stewart 10 40 27 25 15 12 13 For instance, "John" is the first name, "Smith" is the last name, "20% is the number of hours per w eek, and yis the hourly rate. Write a program that computes the weekly salary of each employee. The program prints the first name, last name, and weekly salary of each employee in a file named "results.txt". You must use a function to read/process the data from the input file and this function must have parametersStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started