I hope you all have had a fantastic day!
My problem is that I do not know how to search after a name of an object (if that even is the right way to put it). But an example is: I have made a student class containing first names, last names, grade and year of birth. One of the students name could be "Isaac". What I want to do is write in the "Command Prompt" a name and the result should be the info of the student name I wrote. If the name is not listed as one of the students, I should be able to try again.
Down here we have my small code. In "search_after_student_name" should be the place where the computer searches through the first_name's of the students to see the info of that student.
#include <iostream>
#include <Windows.h>
#include <cstring>
using namespace std;
class Student {
public:
string first_name;
string last_name;
char grade;
int birth;
Student(string aFirst_name, string aLast_name, char aGrade, int aBirth) {
first_name = aFirst_name;
last_name = aLast_name;
grade = aGrade;
birth = aBirth;
}
};
void search_after_student_name(string hisFirst_name)
{
if (hisFirst_name != student.first_name) //Is not like that, but just an example of how I am going to use it
cout << "We couldn't find the name you wrote. Try again" << endl;
else() //if the "hisFirst_name" matches a student:
{
cout << "info about this student...";
}
}
int main()
{
SetConsoleCP(1252);
SetConsoleOutputCP(1252);
Student student1("Oliver", "Twist", 'C', 1999);
Student student2("James", "Free", 'D', 2000);
Student student3("Isaac", "Lee", 'A', 2000);
string namn;
cout << "Write in the name that you want to search: ";
cin >> namn;
search_after_student_name(namn);
return 0;
}
I hope you understand my problem with my silly code and help me. Thanks!