FY-1-b Design a student class in easy way

Design a student class in C++

Design the class student containing getData() and displayData() as two of its
methods which will be used for reading and displaying the student information
respectively.Where getData() will be private method.

Click here to get other OOP Practical

FYIT practical 1-b

#include<iostream>
using namespace std;
class Student
{
   string sname, sid, scourse, sadrs;
   public:
   Student()
   {
       getData();
   }
 
   void displayData()
   {
       cout<<"n Name : "<<sname<<"n ID : "<<sid<<"n Course : "<<scourse<<"n Address : "<<sadrs;
    }

    private:

   void getData()
   {
       cout<<"Enter Student details";
       cout<<"nName : ";
       cin>>sname;
       cout<<"ID : ";
       cin>>sid;
       cout<<"Cousre : ";
       cin>>scourse;
       cout<<"Address : ";
       cin>>sadrs;
   }
};

//itvoyagers.in

int main()
{
   Student stud1 = Student();
   stud1.displayData();
   return 0;
}

 

Output

fyit-oop-practical-design-a-student-class-itvoyagers

Check out more FYIT OOP Practical Program and other logic building programs in C++

We are aiming to explain all concepts of C++ and OOP in easiest terms as possible.
ITVoyagers-logo
ITVoyagers
Author

Leave a Comment