Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ Programming: Having some trouble with this one, please help! You are given a

ID: 645751 • Letter: C

Question

C++ Programming:

Having some trouble with this one, please help!

You are given an input file (say Lab8_P1_InputFile.txt) with the following data:

Alex Antonio 9 1

John Jeffrey 14 0

Sala Kutha 12 1

Sara David 15 1

Tiffany Peterson 6 0

Justin Alberto 9 0

Nancy Scott 12 1

Each input line consists of a student's first name, last name, number of credits registered for the current term, and a flag that indicates whether the student is eligible for in-state tuition rate or not (1 means in-state rate, and 0 means out-state rate). For example, in the first input line, the first name of the student is Alex, the last name is Antonio, the number of registered credit hours is 9, and the student is eligible for in-state tuition rate.

Write a program that reads data from the specified input file and stores the output in an output file (say Lab8_P1_OutputFile.txt). Tuition per credit hour is $350 for in-state students and $570 for outstate students. You need to read the information for each student from the input file, compute the total tuition amount, and then write the required information into the output file.

For each student, the data must be written into the output file in the following format: lastName, firstName [tab][tab]NumberOfCreditsRegistered [tab][tab]TotalTuitionAmount. For example, the first line in the output file should be as below: Antonio, Alex 9 3150

Explanation / Answer

Required Solution:

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main()
{
string firstname,lastname;
int numcredits,flag,total;
ifstream infile ("Lab8_P1_InputFile.txt");
ofstream outfile ("Lab8_P1_OutputFile.txt)");
ifstream outfilech ("Lab8_P1_OutputFile.txt)");
if (infile.is_open() & outfile.is_open())
{
cout<<"start copy"<<endl;
while ( infile>>firstname>>lastname>>numcredits>>flag )
{
if(flag==0)
outfile<<firstname<<" "<<lastname<<" "<<numcredits<<" "<<flag<<" "<<350*numcredits<<endl;
else
outfile<<firstname<<" "<<lastname<<" "<<numcredits<<" "<<flag<<" "<<570*numcredits<<endl;
}
infile.close();
outfile.close();
cout<<"done"<<endl;
}
  
else cout << "Unable to open input/output file"<<endl;
if (outfilech.is_open())
{
cout<<"start print"<<endl;
while ( outfilech>>firstname>>lastname>>numcredits>>flag >>total)
{
cout<<firstname<<" "<<lastname<<" "<<numcredits<<" "<<flag<<" "<<total<<endl;
}
outfilech.close();
cout<<"done"<<endl;
}
}

Input file:Lab8_P1_InputFile.txt

Alex Antonio 9 1
John Jeffrey 14 0
Sala Kutha 12 1
Sara David 15 1
Tiffany Peterson 6 0
Justin Alberto 9 0
Nancy Scott 12 1

Sample Output file:Lab8_P1_OutputFile.txt

Alex    Antonio 9       1       5130

John    Jeffrey 14      0       4900

Sala    Kutha   12      1       6840   

Sara    David   15      1       8550   

Tiffany Peterson        6       0       2100

Justin  Alberto 9       0       3150

Nancy   Scott   12      1       6840

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote