You are on page 1of 6

Program-1

AIM - Program to write student name ,class ,roll number,and age


using class.

CODE-
#include<iostream>

using namespace std;

class student

int age,clas,roll_no;

char name[20];

public:

void getdata(void);

void display(void);

};

void student::getdata()

cout<<"\n"<<"enter the name of student\n";

cin>>name;

cout<<"enter the clas of student \n";


cin>>clas;

cout<<"enter the roll number\n";

cin>>roll_no;

cout<<"enter the age of student\n";

cin>>age;

void student ::display()

cout<<"name ,clas,roll_)no and age \n";

cout<<name<<"\n"<<clas<<"\n"<<roll_no<<"\n"<<age;

int main()

int i,n;

cout<<"ente the number of student\n";

cin>>n;

char A[n];

for(i=0;i<n;i++)

student A[i];
A[i].getdata();

A[i].display();

return 0;

OUTPUT :
Program-2
AIM –Write a program to calculate distance between two points in
x-y coordinate system using class.Take x and y from the user.

CODE-
#include<iostream>

#include<math.h>

using namespace std;

class point

float x[2],y[2];

public:

int i;

void getnumber(void);

};

void point::getnumber()

cout<<"enter the x cordinate\n";

for(i=0;i<2;i++)
{

cin>>x[i];

cout<<"enter the y cordinate\n";

for(i=0;i<2;i++)

cin>>y[i];

float D;

D=sqrt(pow((x[1]-x[0]),2)+pow((y[1]-y[0]),2));

cout<<"distance between the points will be\n"<<D;

int main()

point p;

p.getnumber();

return 0;

OUTPUT :

You might also like