0% found this document useful (0 votes)
54 views6 pages

Ratan 1

The document contains code for two C++ programs that use classes. The first program defines a student class to store and output the name, class, roll number, and age of students. It takes user input for multiple student objects and displays the stored data. The second program defines a point class to calculate and output the distance between two points in an x-y coordinate system by taking x and y values from the user.

Uploaded by

ratan lal mourya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views6 pages

Ratan 1

The document contains code for two C++ programs that use classes. The first program defines a student class to store and output the name, class, roll number, and age of students. It takes user input for multiple student objects and displays the stored data. The second program defines a point class to calculate and output the distance between two points in an x-y coordinate system by taking x and y values from the user.

Uploaded by

ratan lal mourya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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