Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem 2: Create an array of classes called \"Student\" that holds data for a s

ID: 3728004 • Letter: P

Question

Problem 2: Create an array of classes called "Student" that holds data for a student. The class should hold the following data: Name of each student Age of each student Address of each student . . The class should have the following functions setdata (sets the all the data for the class) displaydata (prints out all the data for the class) a complete c++ program that creates an array of instances of the class "Student". The program k the user to enter how many students to create, then ask and store the information for each the array of classes. Then the program should printout the data for each student. Use the should as student in "new" operator to dynamically allocate memory for the array of classes and don't forget to free up the memory.

Explanation / Answer

#include<iostream>
#include<string>

using namespace std;

class Student
{
    // Access specifier
    public:
    // Data Members
    string name;
    int age;
    string address;
  
    void setName(string n){
       name = n;
   }
  
   void setAge(int a){
       age = a;
   }

    void setAddress(string add){
        address = add;
   }
  
   void printName(){
       cout<<"Name = "<<name<<endl;
   }
  
   void printAge(){
       cout<<"Age = "<<age<<endl;
   }

    void printAddress(){
        cout<<"Address = "<<address<<endl;
   }
};


int main(){
   Student student = new Student();
   string name,address;
   int age;
   cout<<"Name: ";
   cin>>name;
   student.setName(name);
   cout<<"Age: ";
   cin>>age;
   student.setAge(age);
   cout<<"Address: ";
   cin>>address;
   student.setAddress(address);
   student.printName();
   student.printAge();
   student.printAddress();
   return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote