Object Oriented Programming Practical 1
Question 1
Write a C++ program to evaluate the following expressions:
X=(-b-(b2-4ac))/2a
expression.cpp
C
#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
clrscr();
int a,b,c,d;
cout<<"Enter value of a,b and c"<<endl;
cin>>a>>b>>c;
d=(-b-(b*b-4*a*c))/(2*a);
cout<<"Value= "<<d<<endl;
getch();
}
Output

Question 2
Write a C++ code to evaluate following expression using input output function: y= 5*x-5 where value of x is taken from user. Find the value of y.
expression1.cpp
C
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int x,y;
cout<<"Enter value of x: "<<endl;
cin>>x;
y=5*x-5;
cout<<"Value of y= "<<y<<endl;
getch();
}
Output

Question 3
Write a program to print “hi” msg if entered value is more than 10 otherwise print “bye” msg on output screen. (Use of Relational operator)
expression2.cpp
C
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int num;
cout<<"Enter a value: "<<endl;
cin>>num;
if(num>10)
cout<<"hi"<<endl;
else
cout<<"bye"<<endl;
getch();
}
Output

Question 4
Write a program to print “hi” msg if entered value is more than 10 otherwise print “bye” msg on output screen. (Use of Relational operator)
largest.cpp
C
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int num1,num2,largest;
cout<<"Enter number 1: ";
cin>>num1;
cout<<"Enter number 2: ";
cin>>num2;
largest=(num1>num2)?num1:num2;
cout<<"Largest number is: "<<largest<<endl;
getch();
}
Output
