This program creates a class Student which has three data members - ID, Name, and Percentage. It has one constructor that takes three arguments - i, n, and s - which are used to initialize the data members. The class also has a display() function which prints out the values of ID, Name, and Percentage. In the main() function, two objects of the Student class are created - s1 and s2 - using the constructor with three arguments. The display() function is then called for each object to print out the values of its data members.
#include <iostream> using namespace std; class Student { public: int ID; string Name; float Percentage; Student(int i, string n, float s) { ID=i; Name=n; Percentage=s; } void display() { cout<<ID<<" "<<Name<<" "<<Percentage<<endl; } }; int main(void) { Student s1=Student(101, "Arun", 93); Student s2=Student(102, "Aswin", 89); s1.display(); s2.display(); return 0; }To download raw file Click Here
101 Arun 93 102 Aswin 89
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions