Vous êtes sur la page 1sur 5

EXERCISES

(CHAPTER 7)

1. #include<iostream>

using namespace std;


class student
{
private:
long int rollno;
int age;
char sex;
float height;
float weight;
public:
void getinfo();
void disinfo();
};

void student::getinfo()
{
cout << " Roll no :";
cin >> rollno;
cout << " Age :";
cin >> age;
cout << " Sex:";
cin >> sex;
cout << " Height :";
cin >> height;
cout << " Weight :";
cin >> weight;
}

void student::disinfo()
{
cout<<endl;
cout<< " Roll no = "<< rollno << endl;
cout<< " Age =" << age << endl;
cout<< " Sex =" << sex << endl;
cout<< " Height =" << height << endl;
cout<< " Weight =" << weight << endl;
}

int main()
{
student s;
s.getinfo();
s.disinfo();
}

5. #ifndef STUDENTS_H_INCLUDED
#define STUDENTS_H_INCLUDED

class students
{
private:
int ID;
double GPA;
public:
students();
students(int ID, double GPA);
void setstudents(int ID, double GPA);
int getID();
double getGPA();
void print();
};
#endif // STUDENTS_H_INCLUDE

#include "students.h"
#include <iostream>
using namespace std;

students :: students()
{
ID = 0;
GPA = 0;
}
students :: students(int ID, double GPA)
{
this -> ID = ID;
this -> GPA = GPA;
}

void students :: setstudents(int ID, double GPA)


{
this -> ID = ID;
this -> GPA = GPA;
}

int students :: getID()


{
return ID;
}
double students :: getGPA()
{
return GPA;
}

void students :: print()


{
cout << "ID : " << ID << endl;
cout << "GPA : " << GPA << endl;

7. #include <iostream

using namespace std;

class point {

private:

int x,y;

public:

point( int xnew, int ynew);

void getdata();

void display(); // constructor with default values

};

// implementation section

point::point(int xnew, int ynew) //constructor

x = xnew;

y = ynew;
}

void point::getdata()

cout << "Enter an integer value \n";

cin >> x;

cout << "Enter an integer value \n";

cin >> y;

void point::display()

cout << "Entered numbers are \n";

cout << " x = " << x << '\t' << " y = " << y << endl;

int main()

point xnew; // declare an object without parameters

point ynew; // declare an object without parameters

return 0;