0% found this document useful (0 votes)
19 views

Lab 6 Exercise 1

This document contains 3 C++ programming exercises that create a student class. Exercise 1 defines a student class with private name and IC data members and public constructor, input, and display methods. It creates a student object and calls its methods. Exercise 2 is similar but creates two student objects and calls methods on both. Exercise 3 adds a destructor to the student class that outputs a message when an object is destroyed.

Uploaded by

babenggila
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Lab 6 Exercise 1

This document contains 3 C++ programming exercises that create a student class. Exercise 1 defines a student class with private name and IC data members and public constructor, input, and display methods. It creates a student object and calls its methods. Exercise 2 is similar but creates two student objects and calls methods on both. Exercise 3 adds a destructor to the student class that outputs a message when an object is destroyed.

Uploaded by

babenggila
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 11

Lab 6 Exercise 1

#include<iostream.h>

class student

private:

char name[20];

char ic[20];

public:

student(); //prototype for constructor

void input();

void display();

};

//constructor for student object

student :: student()

cout<<"Welcome to PSP";

void student::input()

cout<<"\n Please Enter Your Name:";

cin>>name;

cout<<"\n Please Enter IC Number:";


cin>>ic;

void student::display()

cout<<"\n";

cout<<name;

cout<<"\n";

cout<<ic;

cout<<"\n";

cout<<"Politeknik Seberang Perai";

cout<<"\n";

void main()

student DTK; //constructor is called

DTK.input();

DTK.display();

}
Lab 6 Exercise 2
#include<iostream.h>

class student

private:

char name[20];

char ic[20];

public:

student(); //prototype for constructor

void input();

void display();

};

//constructor for student object

student :: student()

cout<<"Welcome to PSP";

void student::input()

cout<<"\n Please Enter Your Name:";

cin>>name;

cout<<"\n Please Enter IC Number:";


cin>>ic;

void student::display()

cout<<"\n";

cout<<name;

cout<<"\n";

cout<<ic;

cout<<"\n";

cout<<"Politeknik Seberang Perai";

cout<<"\n";

void main()

student DTK,DTK1; //constructor is called twice

DTK.input();

DTK.display();

DTK1.input();

DTK1.display();

}
Lab 6 Exercise 3
#include<iostream.h>

class student

private:

char name[20];

char ic[20];

public:

student(); //prototype for constructor

~student(); //prototype for destructor

void input();

void display();

};

//constructor for student object

student :: student()

cout<<"Welcome to PSP";

//destructor for student

student::~student()

cout<<"Thank You\n";
}

void student::input()

cout<<"\n Please Enter Your Name:";

cin>>name;

cout<<"\n Please Enter IC Number:";

cin>>ic;

void student::display()

cout<<"\n";

cout<<name;

cout<<"\n";

cout<<ic;

cout<<"\n";

cout<<"Politeknik Seberang Perai";

cout<<"\n";

void main()

student DTK; //constructor is called

DTK.input();
DTK.display();

You might also like