Object Oriented Programming Practical 3

Question 1
Find the area of the rectangle by casting double data into float and int type.
area.cpp
C
				#include<iostream.h>
#include<conio.h>

void main() 
{
    double l,w;
    float area_float;
	int area_int;
    cout << "Enter the length of rectangle: ";
    cin >> l;
    cout << "Enter the width of rectangle: ";
    cin >> w;
	area_float=(float)(l*w);
	area_int=(int)(l*w);
	cout<<"Area in float: "<<area_float<<endl;
	cout<<"Area in int: "<<area_int<<endl;
	getch();
}
			
Output
Question 2
Write a program which show the use of implicit type casting to calculate the average of two numbers.
average.cpp
C
				#include<iostream.h>
#include<conio.h>

void main() 
{
    int num1, num2;
    float average;
    cout << "Enter the first number: ";
    cin >> num1;
    cout << "Enter the second number: ";
    cin >> num2;
	average=(num1+num2)/2.0;
	cout<<"Average is: "<<average;
	getch();
}
			
Output
Question 3
Calculate average of two numbers using explicit type casting
average.cpp
C
				#include<iostream.h>
#include<conio.h>

void main() 
{
    int num1, num2;
    float average;
    cout << "Enter the first number: ";
    cin >> num1;
    cout << "Enter the second number: ";
    cin >> num2;
	average=(float)(num1+num2)/2;
	cout<<"Average is: "<<average;
	getch();
}
			
Output
Question 4
Write a program which display the percentage of students which accept marks of three subjects from user.(Show the use of Implicit type casting)
percent.cpp
C
				#include<iostream.h>
#include<conio.h>

void main() 
{
    int mark1, mark2, mark3;
    float percent;
    cout << "Enter subject 1 marks: ";
    cin >> mark1;
	cout << "Enter subject 2 marks: ";
    cin >> mark2;
	cout << "Enter subject 3 marks: ";
    cin >> mark3;
	percent=(mark1+mark2+mar3)*100/300.0;
	cout<<"Percent is: "<<percent;
	getch();
}
			
Output

Watch full practical here

Leave a Comment

Your email address will not be published. Required fields are marked *