Object Oriented Programming Practical 3
Question 1
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 2
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
