0% found this document useful (0 votes)
14 views8 pages

Solution Lab - 04

Uploaded by

Zohaib Javed
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)
14 views8 pages

Solution Lab - 04

Uploaded by

Zohaib Javed
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/ 8

4.2.

LAB ACTIVITIES

4.2.1. Program No 1
Write a program to input two numbers, and check if the inputted second number is the square of
first or not. (i.e., a2 = b)

#include<iostream>
#include <conio.h>
using namespace std;

int main()
{ int a, b;

cout<<"Enter first number";


cin>>a;

cout<<"Enter Second number";


cin>>b;

if(a*a==b)
{ cout<<"The second number is the square of first"<<endl;
}
getch();
}

4.2.2. Program No 2
Write a program that input three numbers, evaluate their average. If the average is greater than
80, print “You are above average”.
#include<iostream>
using namespace std;

int main()
{ int a, b, c;
cout<<"Enter first number";
cin>>a;

cout<<"Enter Second number";


cin>>b;
cout<<"Enter third number";
cin>>c;

int avg;
avg=(a+b+c)/3;

cout<<"The average is "<<avg;


if(avg>80)
{cout<<"You are above average";
}

4.2.3. Program No 3
Write a program that finds largest of three inputted numbers.

#include<iostream>
using namespace std;

int main()
{ int a, b, c, max;
cout<<"Enter first number";
cin>>a;

cout<<"Enter Second number";


cin>>b;

cout<<"Enter third number";


cin>>c;

max=a;
if(b>max)
{ max=b;
}
if(c>max)
max=c;
cout<<"The maximum number is: " <<max;
}

4.2.4. Program No 4
Write a program that inputs a number, and finds whether it’s even or odd.

#include<iostream>
#include <conio.h>
using namespace std;

int main()
{ int a;

cout<<"Enter number to find if its even or odd";


cin>>a;

if(a/2==0)
{ cout<<"The number is even"<<endl;
}
else
{ cout<<"The number is odd";
}
getch();
}

4.2.5. Program No 5
Write a program that inputs salary and grade. It adds 50% bonus if grade is greater than 15. It
adds 25% bonus if grade is 15 or less, and then displays the total salary.

#include<iostream>
#include <conio.h>
using namespace std;

int main()
{ int a,b,c;

cout<<"Enter your salary";


cin>>a;

cout<<"Enter your grade";


cin>>b;

if(b>15)
{ c=a+(a*0.5);
cout<<"Now your salary is"<< c<<endl;
}
else if(b<=15)
{ c=a+(a*0.25);
cout<<"Now after increment your salary is "<<c;
}
getch();
}
4.2.6. Program No 6

Write a program that inputs test marks of a student and displays his grade on the following
criteria:
Marks Grade
>=90 A
80 – 89 B
70 – 79 C
60 – 69 D
Below 60 F
#include<iostream>
#include <conio.h>
using namespace std;

int main()
{ int a;

cout<<"Enter your marks";


cin>>a;

if(a>=90)
{
cout<<"Your grade is A"<<endl;
}
else if(a>=80)
{
cout<<"Your grade is B"<<endl;
}

else if(a>=70)
{
cout<<"Your grade is C"<<endl;
}
else if(a>=60)
{
cout<<"Your grade is D"<<endl;
}

else
{
cout<<"Your grade is F"<<endl;
}
getch();
}

4.2.7. Program No 7
Write a program that inputs two numbers, and a character operator (+,-,*, /), and perform the
specified operation on numbers.

#include<iostream>
#include <conio.h>
using namespace std;

int main()
{ int a,b;
char c;

cout<<"Enter first number";


cin>>a;

cout<<"Enter second number";


cin>>b;

cout<<"Enter operation to perform";


cin>>c;

if(c=='+')
{
cout<<"The addition of numbers is: "<<a+b<<endl;
}
else if(c=='-')
{
cout<<"The subtraction of numbers is: "<<a-b<<endl;
}

else if(c=='*')
{
cout<<"The multiplication of numbers is"<<a*b<<endl;
}
else if(c=='/')
{
cout<<"The division of numbers is: "<<a/b<<endl;
}

else
{
cout<<"You have entered wrong character"<<endl;
}

getch();
}

4.2.8. Program No 8
Write a program that inputs 3 numbers and displays the smallest number using nested if
statement.

#include<iostream>
using namespace std;

int main()
{ int a, b, c;
cout<<"Enter first number";
cin>>a;

cout<<"Enter Second number";


cin>>b;

cout<<"Enter third number";


cin>>c;

if(a<b)
{
if(a<c)
cout<<a<<" is the smallest number";
else
cout<<c<<" is the smallest number";
}
Else
{
if(b<c)
cout<<b <<" is the smallest number";
else
cout<<c<<" is the smallest number";
}
}

4.2.9. Program No 9
Write a program that inputs three numbers, and check whether they are equal or not.

#include<iostream>
using namespace std;

int main()
{ int a, b, c;
cout<<"Enter first number";
cin>>a;

cout<<"Enter Second number";


cin>>b;

cout<<"Enter third number";


cin>>c;

if(a==b)
{
if(a==c)
cout<<"All numbers are equal";
else
cout<<"Numbers are different";
}
else

cout<<"Numbers are different";


}

3.8.10. Program No 10

Write a program in C++ that takes a character from the user and tells whether it is a ‘SMALL
CASE’ or ‘CAPITAL CASE’ letter using nested if-else statement only.

#include<iostream>

using namespace std;

int main()

char ch;

cout<<"Enter a character: ";


cin>>ch;

if (ch>='a')

if(ch<='z')

cout<<ch<<" is small letter alphabet";

else if(ch>='A')

if(ch<='Z')

cout<<ch<<" is a Capital letter alphabet";

else

{cout<<"You entered wrong character";

You might also like