Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please write in C++! For this lab, you will write a Student class and use a one-dimensional array of Student objects to represent the students

Please write in C++!

For this lab, you will write a Student class and use a one-dimensional array of Student objects to represent the students in a particular course. Finally, you will write a program that allows the user to enter data about each student in the array, and then search the array to retrieve the data.Begin by writing the Student class definition. The class should contain two data members: a name and an ID number; you should choose appropriate types for each. The class should also contain the following functions:Constructor: The constructor should take no arguments, and should set the instance's data members to suitable initial values.setData: This function should receive new values for both data members and assign the instance's data members appropriately.Accessor functions: These functions should return the current values for each data member, and should have appropriate names.Write a simple main function that allows you to test your Student class thoroughly before continuing.Once you are satisfied that your class is correct, write a main function that implements the following steps.1.Declare an array of 3 Studentobjects2.For each student in the array, prompt the user to enter a name and an IDnumber3.Until the user wants to quit, do the following:a.ask the user whether s/he wants to quit or to search the student list by name or by id number,and read in the response b.read in the name or ID number of the student to be found c.search the list of students and print the other piece of data (that is, if searching by name, print the student's ID number, and vice versa)d.if no matching student is found, print an error message)

Here's what I have:

#Lab_0.h

#include

using namespace std;

class Student {

private:

string name;

int id;

public:

Student() : name{""}, id{0} {}

# getter function

int getID() const { return id; }

string getName() const { return name; }

# setter function

void setData();

};

#Lab_0.cpp

void Student::setData()

{

std::cout << "Enter student name" << std::endl;

std::cin >> name;

std::cout << "Enter student ID" << std::endl;

std::cin >> id;

}

#main.cpp

#include "Lab_0.h"

#include

#include

using namespace std;

int main()

{

Student student;

Student studentArr[3];

for(int i=0; i < sizeof(studentArr); i++)

{

cout << "For student " << i << " : " << endl;

student[i].setData();

}

char opt = 'y';

while(opt != 'n')

{

string search;

std::cout << "Would you like to search by student name or ID number? Enter 'n' to quit. ";

std::cin >> search;

for(int i=0; i < sizeof(studentArr); i++)

{

if(search == studentArr[i])

{

std::cout << studentArr[i];

}

else

{

std::cout << "Error. Student does not exist.";

}

}

}

}

The issue with with "studentArr[i]", but I'm not sure how I would fix this so to align the data types? Can you please explain how I would make this program work?

Thank you!

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Manga Guide To Databases

Authors: Mana Takahashi, Shoko Azuma, Co Ltd Trend

1st Edition

1593271905, 978-1593271909

More Books

Students also viewed these Databases questions