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

PLEASE HELP WITH THIS C++ PROBLEM: Seven students are registered for Fall 2015 a

ID: 3680477 • Letter: P

Question

PLEASE HELP WITH THIS C++ PROBLEM:

Seven students are registered for Fall 2015 at WSU. You are given an input file (say Lab8_P1_InputFile.txt) with the following data:

Alex Antonio 9 1 John Jeffrey 14 0 Bart Simpson 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

Note: Please follow the provided format.

Thank you

Explanation / Answer

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <conio.h>
#include <iomanip>

using namespace std;

int main() {

FILE *fp;

char another;

struct student {

char first_name[50], last_name[50];

int credits, flag;

};

struct student e;

long int recsize;

fp=fopen("Lab8_P1_InputFile.txt","rb+");

if (fp == NULL) {

fp = fopen("Lab8_P1_InputFile.txt","wb+");

if (fp==NULL)
{
puts("Cannot open file");

return 0;
}
}


recsize = sizeof(e);

fseek(fp,0,SEEK_END);

another ='Y';
  
while(another == 'Y' || another == 'y'){

system("cls");
  
cout << "Enter the Firt Name : ";

cin >> e.first_name;

cout << "Enter the Last Name : ";

cin >> e.last_name;

cout << "Enter the Credits : ";

cin >> e.credits;

cout << "Enter the Flag : ";

cin >> e.flag;

fwrite(&e,recsize,1,fp);

cout << " Add Another Record (Y/N) ";

fflush(stdin);

another = getchar();

}
ofstream Lab8_P1_OutputFile;

outputFile.open("Lab8_P1_OutputFile.txt")

system("cls");

rewind(fp);

Lab8_P1_OutputFile<< " LastName"<<","<<"FirstName"<<"           "<<"NumberOfCredits"<<"           "<<"TotalTuitionFee";

while (fread(&e,recsize,1,fp) == 1){

if (e.flag == 1){
  
   Lab8_P1_OutputFile<< " e.last_name"<<","<<"e.first_name"<<"       "<<e.credits<<               "<<"350";
}
if (e.flag == 0){

   Lab8_P1_OutputFile<< " e.last_name"<<","<<"e.first_name"<<"       "<<e.credits<<               "<<"570";
}

Lab8_P1_OutputFile.close();
  
return 0;

}

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