C++ program for student details using array of objects

Array of Objects in C++

Array of Object is similar to creating array or integer, character or any primitive data types.

Example

Array of integer is

int age[5]={1,2,3,4,5};

Similar way array of Students is

Student s[5]={studentObj1,studentObj2,studnetObj3,studentObj4,studentObj5};

The student is class Name

s is an array of objects of 5 elements

To initialize the student object two methods are used here

  1. Initialize student object from a constructor
  2. Create a function to get input from the user to initialize the student object.

Example: C++ program for student details using array of objects

  1. Create a class name student
  2. Declare necessary fields for student as name,age and rollno as a private member of class.
  3. In public section create constructor to initialize value from it
  4. also create a show function to show/ print user data.

To copy the local array variable name to the Student class name strcpy() is used

Here Student constructor is used to initializing student object.

Result

Get User Input for Student Objects

  1. create a class student
  2. declare fields of student as private data member
  3. create a function getStudent() to get input from user and assign it to student data members
  4. create a function showStudent() to show student object details to user.
  5. create a main method and define size of student object
  6. loop student object to take input from user
  7. loop student objcet to show student object details from array of object.

Example: c++ program to display 5 student details using class and object

Output

Here we discussed the C++ program for student details using an array of objects if you found helpful then please share.

Read More

  1. C++ program for student details
  2. Anonymous Object in C++
  3. Lowercase character to uppercase character
  4. Command Line Argument
  5. Local vs Global Object in C++
  6. Local and Nested Classes in C++
  7. Arithmetic operations using switch case
  8. Switch Case in C Programming
  9. Constructor in C++
  10. Know more about C++

Categories C++