0% found this document useful (0 votes)
6 views

LAB TASK 4 Abdullah khalid

The document contains multiple C++ programs that demonstrate basic programming concepts such as user input, conditional statements, and arithmetic operations. Each program is accompanied by an algorithm outlining the steps taken to achieve the desired functionality, including checking for squares, determining positivity, finding multiples, grading based on marks, and calculating bonuses. The programs collectively illustrate fundamental programming techniques suitable for beginners.

Uploaded by

mohibsaeed2014
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)
6 views

LAB TASK 4 Abdullah khalid

The document contains multiple C++ programs that demonstrate basic programming concepts such as user input, conditional statements, and arithmetic operations. Each program is accompanied by an algorithm outlining the steps taken to achieve the desired functionality, including checking for squares, determining positivity, finding multiples, grading based on marks, and calculating bonuses. The programs collectively illustrate fundamental programming techniques suitable for beginners.

Uploaded by

mohibsaeed2014
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/ 15

M.

Abdullah khalid 035

PF lab 4
LAB TASK

Program 1;
#include <iostream>

using namespace std;

int main(){
int num1,num2;
cout<<"Enter you num1:";
cin>>num1;
cout<<"Enter you num2:"<<endl;
cin>>num2;
if(num1*num1==num2){
cout<<"The number 2 is square of num1"<<endl;

Output;
Algorithm;

 Declare two integer variables num1 and num2.


 Display a prompt to the user to enter the value of num1.
 Read the input for num1 from the user.
 Display a prompt to the user to enter the value of num2.
 Read the input for num2 from the user.
 Use an if statement to check if the square of num1 is equal to num2.
 If the condition in the if statement is true, print a message indicating that "The
number 2 is the square of num1."
 End the program.

Program 2;
#include <iostream>

using namespace std;

int main()
{
int a;
cout<<"enter a:";
cin>>a;

if(a>0){
cout<<"a is positive"<<endl;
}
else if(a<0){
cout<<"a is negative"<<endl;
}

else{
cout<<"the number is zero"<<endl;
}
}

Output;

Algorithm;

 Display "enter a:" to prompt the user.


 Read the integer input from the user and store it in variable 'a'.
 If 'a' is greater than 0:
- Display "a is positive."
Else if 'a' is less than 0:
- Display "a is negative."
Else:
- Display "the number is zero."
 End the program.

Program 3;

#include <iostream>

using namespace std;

int main(){
int a,b;
cout<<"Enter any number1"<<endl;
cin>>a;
cout<<"Enter any number2"<<endl;
cin>>b;

if(a%b==0 or b%a==0){
cout<<"second number is multiple of first number"<<endl;
}
}

Output;
Algorithm;

 Declare variables to store the two numbers


 Prompt the user to enter the first number and read the input
 Prompt the user to enter the second number and read the input
 Check if either the first number is a multiple of the second number or the second
number is a multiple of the first number
 End the program

Program 4;
#include <iostream>
using namespace std;
int main(){
int a;
cout<<"Enter you marks :";
cin>>a;
if(a>=90){
cout<<"A grade:";
}
if(a<90&&a>=80){
cout<<"B grade:";
}
if(a<80&&a>=70){
cout<<"C grade:";
}
if(a<70 && a>=60){
cout<<"D grade:";
}
if(a<60){
cout<<"F grade:";
}

Output;

Algorithm;
 Input a (integer): // Get the input marks.

 If a >= 90:
Output: "A grade"
 Else, if 80 <= a < 90:
Output: "B grade"

 Else, if 70 <= a < 80:


Output: "C grade"

 Else, if 60 <= a < 70:


Output: "D grade"

 Else:
Output: "F grade"

Program 5;
#include <iostream>

using namespace std;

int main()
{
int a,b,c;
cout<<"Enter a"<<endl;
cin>>a;
cout<<"Enter b"<<endl;
cin>>b;
cout<<"Enter c"<<endl;
cin>>c;
if(a>b and a>c){
cout<<"a is greatest";
}
else if(b>a and b>c){
cout<<"b is greatest";
}
else{
cout<<"c is greatest";
}
}

Output;

Algorithm;
 Prompt the user to enter three integers a, b, and c.
 Read the values of a, b, and c from the user.
 Use conditional statements (if and else if) to compare the values of a, b, and c
to determine the greatest among them.
 Display the result indicating which variable is the greatest.
Program 6;
#include <iostream>

using namespace std;

int main(){
int a,b,c, avg ,sum;
cout<<"Enter your marks 1:";
cin>>a;
cout<<"Enter your marks 2:";
cin>>b;
cout<<"Enter your marks 3:";
cin>>c;
sum =a+b+c;
cout<<"your sum is:"<<sum<<endl;
avg=sum/3;
cout<<"Your average is :"<<avg;
}

Output;
Algorithm;

 Start
 Declare variables: a, b, c, avg, sum
 Display "Enter your marks 1:"
 Read input for 'a'
 Display "Enter your marks 2:"
 Read input for 'b'
 Display "Enter your marks 3:"
 Read input for 'c'
 Calculate sum = a + b + c
 Display "Your sum is:" followed by the value of 'sum'
 Calculate avg = sum / 3
 Display "Your average is:" followed by the value of 'avg'
 End

Program 7;
#include<iostream>

using namespace std;

int main(){

int salary,salary1,salary2,grade,bonus;
cout<<"Enter your salery :";
cin>>salary;
cout<<"Enter also grade:";
cin>>grade;
if(grade>15){
bonus=salary*50/100;
salary1=salary+bonus;
cout<<"Salary ater 50 % bonus is :"<<salary1;
}
else if (grade<=15){
bonus = salary*25/100;
salary2=salary+bonus;
cout<<"Salary after 25 % bonus is :"<<salary2;
}
else {
cout<<"The total salary is:"<<salary;
}

Output;

Algorithm;
 Get the input for salary (employee salary) from the user.
 Get the input for grade (employee grade) from the user.
 Check if grade is greater than 15.
 If true, calculate a 50% bonus on salary.
 Set bonus to salary * 50 / 100.
 Set salary1 to salary + bonus.
 Display "Salary after 50% bonus is: salary1".
 If false, check if grade is less than or equal to 15.
 If true, calculate a 25% bonus on salary.
 Set bonus to salary * 25 / 100.
 Set salary2 to salary + bonus.
 Display "Salary after 25% bonus is: salary2".
 If both conditions are false, display "The total salary is: salary".
 Display the calculated salary or the original salary based on the conditions.

Program 8;
#include <iostream>

using namespace std;


int main(){
int n1,n2,n3,n4,n5;
cout<<"Enter num1:";
cin>>n1;
cout<<"Enter num2:";
cin>>n2;
cout<<"Enter num3:";
cin>>n3;
cout<<"Enter num4:";
cin>>n4;
cout<<"Enter num5:";
cin>>n5;
if(n1>n2&&n1>n3&&n1>n4&&n1>n5){
cout<<"n1 greatest and n5 n2 n3 n4 are small:";
}
else if(n2>n1&&n2>n3&&n2>n4&&n2>n5){
cout<<"n2 greatest and n1 n5 n3 n4 are small:";
}

else if(n3>n2&&n3>n1&&n3>n4&&n3>n5){
cout<<"n3 greatest and n1 n2 n5 n4 are small:";
}

else if(n4>n2&&n4>n3&&n4>n1&&n4>n5){
cout<<"n4 greatest and n1 n2 n3 n5 are small:";
}
else if(n5>n1&&n5>n2&&n5>n3&&n5>n4){
cout<<"N5 is greatest and n1 n2 n3 n4 are small:";
}

Output;
Algorithm;
 Initialize variables n1, n2, n3, n4, n5 to store the input numbers.
 Prompt the user to enter num1 and store the input in n1.
 Prompt the user to enter num2 and store the input in n2.
 Prompt the user to enter num3 and store the input in n3.
 Prompt the user to enter num4 and store the input in n4.
 Prompt the user to enter num5 and store the input in n5.
 Check the following conditions to find the greatest number:
a. If n1 is greater than n2, n3, n4, and n5, then output "n1 is greatest and n5, n2, n3, n4 are small."

b. Else if n2 is greater than n1, n3, n4, and n5, then output "n2 is greatest and n1, n5, n3, n4 are small."

c. Else if n3 is greater than n1, n2, n4, and n5, then output "n3 is greatest and n1, n2, n5, n4 are small."

d. Else if n4 is greater than n1, n2, n3, and n5, then output "n4 is greatest and n1, n2, n3, n5 are small."

e. Else if n5 is greater than n1, n2, n3, and n4, then output "n5 is greatest and n1, n2, n3, n4 are small."

End of the program.

You might also like