Вы находитесь на странице: 1из 5

Experiment No.

2
PART B
(PART B: TO BE COMPLETED BY STUDENTS)
(Students must submit the soft copy as per following segments within two hours of the
practical. The soft copy must be uploaded on the Blackboard or emailed to the concerned
lab in charge faculties at the end of the practical in case the there is no Black board access
available)
Roll No.H043
Name:Rushin Shah
Program:Btech
Division:H
Semester:2nd
Batch :H3
Date of Experiment: 18/1/16
Date of Submission: 1/2/16
Grade :

B.1 Software Code written by student:


(Paste your C++ code completed during the 2 hours of practical in the lab here)
P1: Modify P1 program of practical no 1, Write a class called DM with data members meter and
centimeter. The class must include member functions 1. convert for converting meter to
centimeters and a display function to display the data of object.
Ans:
#include<iostream.h>
#include<conio.h>
class convert
{
int cm,m;
public:
void input()
{
cout<< enter the value in metres:;
cin>>m;
}
void convt()
{
cm=m*100; }
void display()
{
cout<< the value in cm is:<<cm;
}
};
void main()

{
convt m;
clrscr();
m.input();
m.convt();
m.display();
getch();
}
P2. Modify P1 (practical 2); add a class DB to store distance in feet and inches (Data
Members) and below member functions:
1. Convert For converting feet into inches
2. Display- For displaying data of objects
ANS.
#include<iostream.h>
#include<conio.h>
class db
{
float feet, inches;
public:
void input()
{
cout<< enter the value in feet:;
cin>>feet;
}
void convert()
{
inches=feet/12;
}
void display()
{
cout<< \n the value in inches is:<<inches;
}
friend void add();
};
class dm
{
int m, cm;
public:
void convert()
{
cout<< value in metre:;

cin>>metre;
cm=m*100;
}
void display()
{
cout<< value in cm:;
cout<<cm;
}
};
void main()
{
clrscr();
db d;
dm a;
a.convert();
a.display();
d.input();
d.convert();
d.display(); getch();
}
P3. Modify P2 (practical 2); Write a program that can read values for the class objects and add
one object of DM with another object of DB. Use friend function to carry out the addition
operation.
ANS:
#include<iostream.h>
#include<conio.h>
class dm;
class db
{
float feet, inches;
public:
void input()
{
cout<< enter value in feet:<<`\n`;
cin>>feet;
}
void convert()
{
inches=feet/12;
}
void display()

{
cout<< value in inches:<<inches;
}
friend void add(db, dm);
};
class dm
{
int m,cm;
public:
void convert() {
cout<< value in metre:<<`\n`;
cin>>m;
cm=m*100;
}
void display()
{
cout<< value in cm:<< `\n`;
cout<<cm;
}
friend void add(dm, db);
};
void add(dm a, db d)
{
int c;
c = a.cm + b.inches;
cout<< sum is<<c;
}
void main()
{
clrscr();
db d;
dm a;
a.convert();
a.display();
d.input();
d.convert();
d.display();
sum(e, b)
getch();
}

B.2 Input and Output:


(Paste your program input and output in following format. If there is error then paste the
specific error in the output part. In case of error with due permission of the faculty extension
can be given to submit the error free code with output in due course of time. Students will be
graded accordingly.)
P1.
Enter the value 3
Cm reading 500
P2.
Value in metre 6
Value in cm 600
Enter value in feet 24
Value in inches 2
P3.
Value in metre 7
Value in feet 24
Sum 702

B.3 Conclusion:
(Students must write the conclusion as per the attainment of individual outcome listed above
and learning/observation noted in section B.1)

Вам также может понравиться