Question

Serve the user in two phases: In C++ Phase A: (1) Read all input records one...

Serve the user in two phases:

In C++
Phase A:
(1) Read all input records one by one into arrays in main memory.
(2) Display all the records on the screen in the order they are read from the input data file.
(3) Do a Selection Sort (must be implemented as a function) to sort the records in ascending
order on STUDENT_ID and display all the full records correctly in the correct order after
sorting.
Phase B:
(1) Then, the user can do the following until he/she chooses to exit Task B:
(1a) Search for a STUDENT by STUDENT_ID (must be implemented as a function)
(1b) If the search STUDENT_ID is found, then after (1a), the system displays the complete
information of this STUDENT on the screen. Then, the user can either subtract or add a
particular number of cents (an integer) to update the current BALANCE of this student once.
(1c) If the search STUDENT_ID is not found, then after (1a), the system displays the
message “Student not found.”
(2) When the user chooses to quit Phase B Step (1), the system writes all records with the
current values for the data fields from the arrays (from slots 0 to the last slots with data) into
a new output file in the same folder and the file name is to be “infoout.txt.” The
record format is to be the same record format as the input file. We expect the order of
records in this new file to be in ascending order on STUDENT_ID.
II. Your program displays “Updating of records done and the new file is: infoout.txt”
and return to the Main Menu

B12345 Abot Mark 600
G98733 Albert Pete 100
A93832 Waltz Manny 300
A32334 Leng Katy 1000
E32145 Rock Keith 80
A09121 Shaffer John 1050
A94321 Lewis Stephen 500
A83243 Chandler Lilly 6300
E38273 Johns Adam 5200

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<iostream>

#include<fstream>

using namespace std;

class student

{

//data variables

public:

string name,id,current;//

};

//method to sort using selection sort

void selectionSort(student s[],int length)

{

int k;

string temp;

for(int i = length -1; i > 0; --i)

{

k = 0;

for(int j = 1; j <= i; ++j)

{

//sorting

if(s[j].name >s[k].name)

{

k = j;

}

//swapping

temp = s[k].name;

s[k].name = s[i].name;

s[i].name = temp;

temp =s[k].id;

s[k].id=s[i].id;

s[i].id=temp;

string tem= s[k].current;

s[k].current = s[i].current;

s[i].current =tem;

}

}

}

void display(student s[],int n)

{

int i=0;

while(i<n)

{

cout<<s[i].id<<' '<<s[i].name<<' '<<s[i].current<<endl;

i++;

}

}

int main()

{

//phaseA

int n;

cout<<"Enter how many records you want to enter:";

cin>>n;

char d;

student s[n];

int i=0;

//reading file

ifstream in("input.txt");//change the file name here

//this will read n records

//assuming in file..records are in below format

//id name currentbalance

while(i<n)

{

//reading from file..

in>>s[i].name;

in>>s[i].id;

in>>s[i].current;

i++;

}

//printing before sorting...

cout<<"\nStudent details before sorting:\n";

display(s,n);

selectionSort(s,n);

cout<<"\nStudent details After sorting:\n";

display(s,n);

int c;

while(1)

{

cout<<"1:Search\n2:Exit\nEnter ur choice:";

cin>>c;

if(c==1)

{

string na;

cout<<"Enter name to search:";

d=getchar();

getline(cin,na);

for(i=0;i<n;i++)

if(s[i].name==na)break;

if(i==n)cout<<"\nNot found\n";

else cout<<"Found at :"<<i<<"\n";

}

else

{

break;

}

}

//phase b

//writing to file

ofstream out("infoout.txt");//opening file...

//writing to file

int k=0;

if(out.is_open())

while(k<n)

{

out<<s[i].id<<" "<<s[i].name<<" "<<s[i].current<<endl;

k++;

}

//closing file

out.close();

return 0;

}

output:

Enter how many records you want to enter:2

Enter name:Waltz Manny

Enter id:a98425

Enter balance:972345

Enter name:Abot Mark

Enter id:b6245

Enter balance:97245

Student details before sorting:

a98425 Waltz Manny 972345

b6245 Abot Mark 97245

Student details After sorting:

b6245 Abot Mark 97245

a98425 Waltz Manny 972345

1:Search

2:Exit

Enter ur choice:1

Enter name to search:

Add a comment
Know the answer?
Add Answer to:
Serve the user in two phases: In C++ Phase A: (1) Read all input records one...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ Lab 1. Read in the contents of a text file up to a maximum of...

    C++ Lab 1. Read in the contents of a text file up to a maximum of 1024 words – you create your own input. When reading the file contents, you can discard words that are single characters to avoid symbols, special characters, etc. 2. Sort the words read in ascending order in an array (you are not allowed to use Vectors) using the Selection Sort algorithm implemented in its own function. 3. Search any item input by user in your...

  • Write a program in C++ to: 1. Read all records from a binary file (also attached...

    Write a program in C++ to: 1. Read all records from a binary file (also attached to this email) to arrays; (the record structure: student number (20 bytes), grade (integer)) 2. Sort the list according to test scores; 3. Calculate the average test score for the class and print on the screen; 4. write sorted records to a new binary file. For example: The records in the original file: 1 89 2 95 3 76 The new file sorted by...

  • In C++, write a complete program that receives a series of student records from the keyboard...

    In C++, write a complete program that receives a series of student records from the keyboard and stores them in three parallel arrays named studentID and courseNumber and grade. All arrays are to be 100 elements. The studentID array is to be of type int and the courseNumber and grade arrays are to be of type string. The program should prompt for the number of records to be entered and then receive user input on how many records are to...

  • Phase one implementation: 1-The menu of selections implemented in main function. 2- Each choice should be...

    Phase one implementation: 1-The menu of selections implemented in main function. 2- Each choice should be implemented in the main function. 3- The data is saved permanently in a file. Problem Description: Assume one of the companies in Qatar who is renting flats for people asks you to develop a small system to help them track who paid the rent fees, and who did not for the coming month. The data in this system includes: ID number of the person...

  • C++ developing involves ut from a file a person's first name, last name, phone number and...

    C++ developing involves ut from a file a person's first name, last name, phone number and birth a menu driven database application. You need to 4) This program accept as input ogram will be menu driven with the following options: 1) Find a person's information 2) Add a person to the database 3) Edit a person's information 4) Display all records to the screen 5) Quit Option 1 allows the user to enter a name after which you will search...

  • in C++ You are to define a structure containing the id number, three test scores, and...

    in C++ You are to define a structure containing the id number, three test scores, and their average, for each student in a class of 20. The file pr2data.txt is included and contains the data. The program is to include the following: A function that reads 20 records of data from the file, finds the average for each student and prints each student’s record. A function that lists the ids and averages for all the students whose average is above...

  • C++ Programming

    PROGRAM DESCRIPTIONIn this project, you have to write a C++ program to keep track of grades of students using structures and files.You are provided a data file named student.dat. Open the file to view it. Keep a backup of this file all the time since you will be editing this file in the program and may lose the content.The file has multiple rows—each row represents a student. The data items are in order: last name, first name including any middle...

  • C++ program Write a C++ program to manage a hospital system, the system mainly uses file...

    C++ program Write a C++ program to manage a hospital system, the system mainly uses file handling to perform basic operations like how to add, edit, search, and delete record. Write the following functions: 1. hospital_menu: This function will display the following menu and prompt the user to enter her/his option. The system will keep showing the menu repeatedly until the user selects option 'e' from the menu. Arkansas Children Hospital a. Add new patient record b. Search record c....

  • This lab is to give you more experience with C++ Searching and Sorting Arrays Given a...

    This lab is to give you more experience with C++ Searching and Sorting Arrays Given a file with data for names and marks you will read them into two arrays You will then display the data, do a linear search and report if found, sort the data, do a binary search. Be sure to test for found and not found in your main program. Read Data Write a function that reads in data from a file using the prototype below....

  • Using C programming For this project, you have been tasked to read a text file with student grade...

    Using C programming For this project, you have been tasked to read a text file with student grades and perform several operations with them. First, you must read the file, loading the student records. Each record (line) contains the student’s identification number and then four of the student’s numerical test grades. Your application should find the average of the four grades and insert them into the same array as the id number and four grades. I suggest using a 5th...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT