C++ language »visual studio 1. Develop a simple student management program for a
ID: 3606624 • Letter: C
Question
C++ language »visual studio 1. Develop a simple student management program for a class that can help the instructor manage the information of all students. You need to design a Class representing a student that includes relevant data fields including as first name, last name, SIU ID, and score. Suppose the class has at most 30 students. Your program should allow the instructor to do the following operations: a) Whenever your program starts, it first reads a file created by you, named "students.txt", which contains the information of students in the class. Suppose each row of the file contains the information of one student. b) List the information of all students one row by one row. n of a student. The program will ask the instructor to input the first and last name of the student. If such a student exists, it will list the information of the c) List the in student. Otherwise, a prompt will be printed to the instructor saying 'not exist'. d) Modify the information of a student. The program will ask the instructor to input the first and last name of the student. If such a student exists, it will further ask the instructor to further input other information of the student. Otherwise, a prompt will be printed to the instructor saying 'not exist'. e) Write updated student information to the "students.txt" file. Each row of the file should contain the information of one student. The above process repeats until the user selects exit. Before exiting the program, the function for requirement d) will be called to write updated student information to the "students.txt" fileExplanation / Answer
#include<iostream>
#include<string>
#include<vector>
#include<fstream>
using namespace std;
struct student{
string first_name;
string last_name;
string SIU_ID;
double score;
};
int main(){
vector<student> data;
student st;
string first_name;
string last_name;
ifstream fin("students.txt");
if (!fin){
cout << "Error opening file :";
return 0;
}
while (fin >>st.first_name >> st.last_name >> st.SIU_ID >> st.score){
data.push_back(st);
}
fin.close();
int ch = 0;
while (ch != 4){
cout << "1.Print all students ";
cout << "2.Search a student ";
cout << "3.Modify students ";
cout << "4.Quit ";
cout << "Enter your choice :";
cin >> ch;
if (ch == 1){
for (int i = 0; i<data.size(); i++)
cout << data[i].first_name << " " << data[i].last_name << " " << data[i].SIU_ID << " " << data[i].score << endl;
}
if (ch == 2){
cout << "Enter first name :";
cin >> first_name;
cout << "Enter last name :";
cin >> last_name;
int found = 0;
for (int i = 0; i<data.size(); i++){
if (data[i].first_name == first_name && data[i].last_name == last_name){
found = 1;
cout << data[i].first_name << " " << data[i].last_name << " " << data[i].SIU_ID << " " << data[i].score << endl;
break;
}
}
if (found == 0)
cout << "Not exist ";
}
if (ch == 3){
cout << "Enter first name :";
cin >> first_name;
cout << "Enter last name :";
cin >> last_name;
int found = 0;
for (int i = 0; i<data.size(); i++){
if (data[i].first_name == first_name && data[i].last_name == last_name){
found = 1;
cout << "Enter new first name :";
cin >> data[i].first_name;
cout << "Enter new last name :";
cin >> data[i].last_name;
cout << "Enter new SIU ID :";
cin >> data[i].SIU_ID;
cout << "Enter new score:";
cin >> data[i].score;
break;
}
}
if (found == 0)
cout << "Not exist ";
}
}
ofstream fout("students.txt");
for (int i = 0; i<data.size(); i++){
fout << data[i].first_name << " " << data[i].last_name << " " << data[i].SIU_ID << " " << data[i].score << endl;
}
fout.close();
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.