Download as pdf or txt
Download as pdf or txt
You are on page 1of 13

NUMERICAL ANALYSIS LAB-02

Assignment No. 02
WEEK 02 LECTURE 01, 02 (PRACTICE QUESTIONS)
PRACTICE QUESTION 01:
Take values of height and width of a rectangle from user and print on the screen whether it is
square or not.

SOLUTION:
#include <iostream>
using namespace std; // NIMRA SHAHID
int main ()
{
int hight, width;
cout<<"Enter the hight:";
cin>>hight;
cout<<"Enter the width:";
cin>>width;
if(hight==width)
{cout<<"It is a Square.";
}
else{
cout<<"It is not a Square.";
}
return 0;
}
PRACTICE QUESTION 02:
Take two int values from user and print greatest among them.

SOLUTION:
#include <iostream>
using namespace std; // NIMRA SHAHID
int main ()
{
int Value1, Value2;
cout<< "Enter Value1:";
cin>> Value1;
cout<< "Enter Value2:";
cin>> Value2;
if(Value1>Value2)
{cout<< "Value1 is greatee then Value2.";
}
if(Value2>Value1)
{cout<< "Value2 is greater then Value1.";
}
else{
cout<< "Value1 is equal to Value2.";
}
return 0;
}
PRACTICE QUESTION 03:
A Book Shop has announced 10% of discount on the total purchased amount if it is greater
than 1000. Let suppose each book cost 100. Ask the number of purchased book, calculate and
print total amount payable to the shop.

SOLUTION:
#include <iostream>
using namespace std; // NIMRA SHAHID
int main ()
{
int Quantity;
cout<< "Enter the Quantity of books:";
cin>>Quantity;
if(Quantity <= 10)
{int cost= Quantity*100; // Cost of one book is 100.
cout<< "The total cost of puchased books is.."<<cost;
}
else{
int cost= (Quantity*100)-((Quantity*100)/10);
cout<< "The total cost of purchased books is.."<<cost;
}
return 0;
}
PRACTICE QUESTION 04:

A company decided to give bonus of 5% to employee if his/her year of service is more than 5
years. Ask user for their salary and year of service and print the net bonus amount.

SOLUTION:
#include <iostream>
using namespace std; // NIMRA SHAHID
int main ()
{
int Salary,years;
cout<< "Enter the Salary of Employee:";
cin>>Salary;
cout<< "Enter the years of service of Employee:";
cin>>years;
if(years>5)
{int Bonus= ((Salary*5)/100);
cout<< "The net Bonus of Employee is "<<Bonus;
}
else{
cout<< "The years of service of Employee is less than 5 so no Bonus.";
}
return 0;
}
PRACTICE QUESTION 05:

A student will not be allowed to sit in exam if his/her attendance is less than 75%.

SOLUTION:
#include <iostream>
using namespace std; // NIMRA SHAHID
int main ()
{
int held,attended;
cout<< "Enter the Number of classes held:";
cin>>held;
cout<< "Enter the Number of classes attended:";
cin>>attended;
{int Percentage= (attended*100)/held;
cout<< "The percentage of attendence is "<<Percentage<<endl;
if(Percentage<75)
cout<< "The student is not allowed to sit in the Exam.";
else
cout<< "The student is allowed to sit in the Exam.";
}
return 0;
}
PRACTICE QUESTION 06:
Take three number as input and print the largest number as output with message.
SOLUTION:
#include <iostream>
using namespace std; // NIMRA SHAHID
int main ()
{
float First, Second, Third;
cout<< "Enter the First number:";
cin>>First;
cout<< "Enter the Second number:";
cin>>Second;
cout<< "Enter the Third number:";
cin>>Third;
{
if(First>Second && First>Third)
cout<< "First number is largest.";
if(Second>First && Second>Third)
cout<< "Second number is largest.";
if(Third>First && Third>Second)
cout<< "Third number is largest.";
}
return 0;
}
WEEK 02 LECTURE 03(PRACTICE PROBLEMS)

PRACTICE PROBLEM 01:


Write a program that take input number and if it is between 40 and 50 (including both 40 and
50) Print Valid Number Otherwise print Invalid Number.

SOLUTION:
#include <iostream>
using namespace std; // NIMRA SHAHID
int main ()
{
int Number;
cout<< "Enter the Number:";
cin>>Number;
{
if(40<=Number && Number<=50)
cout<< "Valid Number.";
else
cout<< "Invalid Number!";
}
return 0;
}
PRACTICE PROBLEM 02:

Write a Program that print valid number if number is between 40 and 50 or it is between 60
and 80.

SOLUTION:
#include <iostream>
using namespace std; // NIMRA SHAHID
int main ()
{
int Number;
cout<< "Enter the Number:";
cin>>Number;
{
if((40<Number && Number<50) || (60<Number && Number<80))
cout<< "Valid Number.";
else
cout<< "Invalid Number!";
}
return 0;
}
PRACTICE PROBLEM 03:
A school has following rules for grading system:
O Below 25 - F
O 26 to 45 - E
O 46 to 50 - D
O 51 to 60 - C
O 61 to 80 - B
O Above 80 - A
Ask user to enter marks and print the corresponding grade.

SOLUTION:
#include <iostream>
using namespace std; // NIMRA SHAHID
int main ()
{
int Marks;
cout<< "Enter the marks of student out of 100:";
cin>>Marks;
if(Marks>0 && Marks<25)
cout<< "The grade of student is 'F'.";
if(Marks>=26 && Marks<=45)
cout<< "The grade of student is 'E'.";
if(Marks>=46 && Marks<=50)
cout<< "The grade of student is 'D'.";
if(Marks>=51 && Marks<=60)
cout<< "The grade of student is 'C'.";
if(Marks>=61 && Marks<=80)
cout<< "The grade of student is 'B'.";
if(Marks>80 && Marks<=100)
cout<< "The grade of student is 'A'.";
if(Marks<=0 || Marks>100)
cout<< "You entered invalid marks!";
return 0;
}

You might also like