How can i access a main class objects from outside the function? / Better Alternative? If i have 4 Student objects how can i print the information for the specific object given one parameter about the class, like the students Idnumber.  What i came up with was making a checkId void function that takes the user input and runs an if else chain checking if the Id belongs to student 1-4 then printing the details of that classes object with the void function print. ideally i would want the if-else chain in the checkId function to call the print( student1-4) class object but im not sure how to properly do that. i dont think this is the best way to go about it, if you have any recommendations or alternatives please help me out.

Systems Architecture
7th Edition
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Stephen D. Burd
Chapter3: Data Representation
Section: Chapter Questions
Problem 12VE
icon
Related questions
Question

Novice: How can i access a main class objects from outside the function? / Better Alternative?

If i have 4 Student objects how can i print the information for the specific object given one parameter about the class, like the students Idnumber. 

What i came up with was making a checkId void function that takes the user input and runs an if else chain checking if the Id belongs to student 1-4 then printing the details of that classes object with the void function print. ideally i would want the if-else chain in the checkId function to call the print( student1-4) class object but im not sure how to properly do that.

i dont think this is the best way to go about it, if you have any recommendations or alternatives please help me out.

gint main() {
char change = 'Y';
int idNum, q1, q2, q3, quizChoice, neWGrade, user, option, repeat = 0;
string name, address, phone;
| /*
Student student1( "student name1", 970875, "126 Orchard" , "(567) 987 - 765", 85, 100, 95 );
Student student2( "student name2", 970876, "268 University Blouvard" , "(956)463-9874", 100, 100, 100 );
Student student3("student name3", 970877, "1987 Mines Rd", "(202) 984-0021", 85, 100, 95);
Student student4("student name4", 970878, "502 San Dario" , "(425) 234-8850", 69, 75, 70);
... */
do {
Transcribed Image Text:gint main() { char change = 'Y'; int idNum, q1, q2, q3, quizChoice, neWGrade, user, option, repeat = 0; string name, address, phone; | /* Student student1( "student name1", 970875, "126 Orchard" , "(567) 987 - 765", 85, 100, 95 ); Student student2( "student name2", 970876, "268 University Blouvard" , "(956)463-9874", 100, 100, 100 ); Student student3("student name3", 970877, "1987 Mines Rd", "(202) 984-0021", 85, 100, 95); Student student4("student name4", 970878, "502 San Dario" , "(425) 234-8850", 69, 75, 70); ... */ do {
void checkId(int id) { //970875, 97O876, 970877, 970878.
if (id == 970875) {
print(); // if id then = student[1] but how do i print info for student[i]?
else if (id
970876) {
==
//student 2
print(); //print Student student2
else if (id
970877) {
==
//student 3
print(); //print student3
else if (id == 970878) {
//studetn 4
}
else {
cout << "Enter valid ID number";
void print(){ //what parameters should i use?
cout << ":
cout <« "Student Name: " « .name < endl; // ? not sure how to print for a given class object
cout <« "Student ID: " « idNumber « endl; // ex: student1.idNumber
cout <« "Student Address: " « address <« endl; // ex: cout <« student3.address
cout <« "Student Telephone number: " <« phone << endl; //ex: student2.phone
cout <« "Quiz Grades: " « quiz1 <« "" « quiz2 « " " « quiz3 <« endl;
cout <« "The students's quiz average is: " <« fixed « setprecision(2) « getAverage();
cout <« "The student's letter grade is :\n";//ifelse letter chain.
cout <<
=\n";
Transcribed Image Text:void checkId(int id) { //970875, 97O876, 970877, 970878. if (id == 970875) { print(); // if id then = student[1] but how do i print info for student[i]? else if (id 970876) { == //student 2 print(); //print Student student2 else if (id 970877) { == //student 3 print(); //print student3 else if (id == 970878) { //studetn 4 } else { cout << "Enter valid ID number"; void print(){ //what parameters should i use? cout << ": cout <« "Student Name: " « .name < endl; // ? not sure how to print for a given class object cout <« "Student ID: " « idNumber « endl; // ex: student1.idNumber cout <« "Student Address: " « address <« endl; // ex: cout <« student3.address cout <« "Student Telephone number: " <« phone << endl; //ex: student2.phone cout <« "Quiz Grades: " « quiz1 <« "" « quiz2 « " " « quiz3 <« endl; cout <« "The students's quiz average is: " <« fixed « setprecision(2) « getAverage(); cout <« "The student's letter grade is :\n";//ifelse letter chain. cout << =\n";
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Data members
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Systems Architecture
Systems Architecture
Computer Science
ISBN:
9781305080195
Author:
Stephen D. Burd
Publisher:
Cengage Learning