Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can someone fix my code. Needs to receive first and last name from user along with 3 scores. It will then take information and store

Can someone fix my code. Needs to receive first and last name from user along with 3 scores. It will then take information and store it into new file along with the average of 3 scores. Here is what I have so far

/* Preprocessor Directives */ #include //Standard IO Stream required for all programs #include //used for string processing #include //file processing using namespace std; //Standard namespace for c programs #pragma warning(disable : 4996) //disable scanf error #define MaxName 20 //largest name allowed #define MaxGrade 3 //largest email address allowed

/* Global Variable */ struct Student { char FirstName[MaxName]; //subelement of structure student for first name char LastName[MaxName]; //subelement of structure student for last name char Grade[MaxGrade]; //subelement of structure student for Grade

}; //end struct student

/* Function Prototype */ void Add(Student NewStudent[], int& i); //Add student fucntion to get new user data

int main() { /* Variables */ char LineIn[100]; //input line from file FILE* Gradebook_ptr; // File pointer to contacts file loaded in memory student GradebookList[20]; //place to store contacts to use within main int i = 0; //loop incrementor int StudentCont = 0; //current person number char Ans; //answer to if the user wants more people y or Y int j = 0;//loop incrementor char LineOut[100]; //line to write to file

/* Process or Main program */

for (j = StudentCont; j < i;j++)// loop for each new student to add to a file {

/* Open and read data from file contacts.txt */ Gradebook_ptr = fopen("", "w"); //open file

if (Gradebook_ptr == NULL) //check to see if file was opened {//if true cout << " **Error File Did Not Open** "; //error message to console system("pause"); //wait for user input (windows only) exit(0); //exit program

}// end if (Contact_ptr == NULL) else {

cout << " file opened correctly "; //file opened }

//read data from file one line at a time store in contact array while (fgets(LineIn, 100, Gradebook_ptr) != NULL) { //break out the input line into first last email and phone sscanf(LineIn, "%s\t%\t%s\t%s", GradebookList[i].FirstName, GradebookList[i].LastName, GradebookList[i].Grade1, GradebookList[i].Grade2, GradebookList[i].Grade3); i++; //incrment loop incrementor

}//end while (fgets(LineIn, 100, Contact_ptr) != NULL)

//store number read in StudentCont = i;

//close file fclose(Gradebook_ptr); }

/* Ask User if they want to add additional people to file */ cout << " Would you like to add additional people to the file (y)?\t"; //instructions to user cin >> Ans; //get answer from user 'y' or 'Y'

while (Ans == 'y' || Ans == 'Y')//loop until received all new persons { //see if we received more then 20 if (StudentCont >= 20) {//if treu cout << " Warning Cant Add Any More students "; //display error message break; //break out of loop

}//if (StudentCont >= 20)

//get new person AddStudent(GradebookList, i);//get new person from user

i++;//increment number of Students

}//end while (Ans == 'y' || Ans == 'Y')

/* Write each new people to file contacts.txt */ if (i > StudentCont) //see if new ppl are requried to add to file {//if true //open file write mode Gradebook_ptr = fopen("", "w");

//error message if file not opened if (Gradebook_ptr == NULL) {//if true

cout << " ***File Not Opened*** "; //error message exit(0); //exit program

}//end if (Gradebook_ptr == NULL) else { cout << " File Opened Corectly 2 "; }

fputc(' ', Gradebook_ptr); //format file

system("pause"); //wait for anykey

return 0; //Return Zero }//End main()

/* Function Definitions */ void AddStudent(Student ContactPeople[], int& i) { /* local variables */

//get first name cout << " Please Enter New First Name:\t";//instructions cin >> NewStudent[i].FirstName; //receive first name

//get last name cout << " Please Enter New Last Name:\t"; //instructions cin >> NewStudent[i].LastName; //get last name

//get Grade1 cout << " Please Enter Grade 1:\t"; //instructions cin >> NewStudent[i].Grade1;//receive grade

///get Grade2 cout << " Please Enter Gradel:\t"; //instructions cin >> NewStudent[i].Grade2;//receive grade

//get Grade3 cout << " Please Enter Grade3:\t"; //instructions cin >> NewStudent[i].Grade3;//receive grade return;//bak to main }//end void AddPerson(Person ContactPeople[], int& i)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Temporal Databases Research And Practice Lncs 1399

Authors: Opher Etzion ,Sushil Jajodia ,Suryanarayana Sripada

1st Edition

3540645195, 978-3540645191

Students also viewed these Databases questions

Question

What is quality of work life ?

Answered: 1 week ago

Question

What is meant by Career Planning and development ?

Answered: 1 week ago

Question

What are Fringe Benefits ? List out some.

Answered: 1 week ago