1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
using namespace std;
class Student
{
public:
int iD;
string firstName;
string lastName;
int examGrade;
bool isdeleted;
Student();
Student(int, string, string, int);
};
void main()
{
Student Info;
Student *records;
int people;
int count = 0;
int option = 0;
cout << "How many people info do you want? ";
cin >> people;
records = new Student[people];
fstream file;
file.open("Records.txt", ios::in);
file << people;
for(int i = 0; i < people; i++)
{
cout << "Please enter the student's id: ";
cin >> Info.iD;
cout << "Please enter the student's first name: ";
cin >> Info.firstName;
cout << "Please enter the student's last name: ";
cin >> Info.lastName;
cout << "Please enter the student's exam grade: ";
cin >> Info.examGrade;
records[i] = Student(Info.iD, Info.firstName, Info.lastName, Info.examGrade);
cout << endl;
file << Info.iD << Info.firstName << Info.lastName << Info.examGrade;
if(i == people-1)
{
cout << "Please enter the ID of the student to be deleted. " << endl;
cout << "To exit, please type -1. " << endl;
cin >> option;
if(option == -1)
{
exit(1);
}
if(option != -1)
{
for(int j = 0; j < people; j++)
{
if(option == records[j].iD)
{
count++;
records[j].isdeleted = true;
}
}
}
}
}
file.close();
file.open("Records.txt", ios:: out);
file << people-count << endl;
for(int j = 0; j < people-count; j++)
{
if(records[j].isdeleted == true)
{
file << records[j].iD << " " << records[j].firstName << " " << records[j].lastName << " " << records[j].examGrade;
}
}
system("pause");
}
Student:: Student()
{}
Student::Student(int iD, string firstName, string lastName, int examGrade)
{
int ID = 0, exam_Grade = 0;
string first_Name, last_Name;
iD = ID;
firstName = first_Name;
lastName = last_Name;
examGrade = exam_Grade;
}
|