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 Student is

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

Student is class Name

s is array of objects of 5 elements

To initialize student object two methods are used here

  1. Initialize student object from constructor
  2. Create a function to get input from user to initialize 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 local array variable name to Student class name strcpy() is used

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.

Output

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++