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

Programm

This document contains 10 programming problems assigned to the student Naeem Tahir with roll number BSELF22022. The problems cover basic C++ concepts like calculating volume of a cylinder, printing patterns, finding area and perimeter, user input/output, if-else conditions, loops, and swapping values. Students are instructed to write C++ code to solve each problem and submit their solutions by June 16th, 2023 for marks. Sample outputs and solutions are provided for each problem.

Uploaded by

matloob subhani
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Programm

This document contains 10 programming problems assigned to the student Naeem Tahir with roll number BSELF22022. The problems cover basic C++ concepts like calculating volume of a cylinder, printing patterns, finding area and perimeter, user input/output, if-else conditions, loops, and swapping values. Students are instructed to write C++ code to solve each problem and submit their solutions by June 16th, 2023 for marks. Sample outputs and solutions are provided for each problem.

Uploaded by

matloob subhani
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 18

Assighnment # 01

Name: Naeem Tahir

Roll# BSELF22022

Assignment of : Computer
Computer Programming
Assignment # 1 (Spring 2023) Marks 10
Due Date: 16 June, 2023
Instruction:
Submit the answer in hard copy till the due date after due date no assignment will be
accepted.

Program # 1: Write a program in C++ to calculate the volume of a cylinder.


Need input & output :
Volume of cylinder=(3.14*radius*radius*height);
Sample Output:
Calculate the volume of a cylinder :
----------------------------------------------
Output
Input the radius of the cylinder : 6
Input the height of the cylinder : 8
The volume of a cylinder is : 904.32

Solution:

#include<iostream>
using namespace std;
int main()
{
int a, b;
cout<<"Put dia of cylinder = ";
cin>>a;
cout<<"Put height of cylinder = ";
cin>>b;
cout<<"____________________________"<<endl;
cout<<"Volume of cylinder = "<<(3.1415*a*a*b);
return 0;
}
Program # 2: Write five C++ statements to print the asterisk pattern as shown below
*****
*****
*****
*****
*****

Solution:
#include<iostream>
using namespace std;
int main()
{
cout<<"*****"<<endl;
cout<<"*****"<<endl;
cout<<"*****"<<endl;
cout<<"*****"<<endl;
cout<<"*****"<<endl;
return 0;
}
Program # 3: Write a program in C++ to find the Area and Perimeter of a Rectangle.
Area = length*width;
Perimeter = 2*(length+width)
Sample Output:
Find the Area and Perimeter of a Rectangle :
-------------------------------------------------
Output
Input the length of the rectangle : 10
Input the width of the rectangle : 15
The area of the rectangle is : 150
The perimeter of the rectangle is : 50

Solution:
#include<iostream>
using namespace std;
int main()
{
int a, b;
cout<<"Put the length of rectangular = ";
cin>>a;
cout<<"Put the width of rectangular = ";
cin>>b;
cout<<"____________________________"<<endl;
cout<<"Area of rectangular = "<<(a*b)<<endl;
cout<<"The perimeter of rectangular = "<<(2*(a+b))<<endl;
return 0;
}
Program # 4: Make a program which will get radius from the user and display area of circle.
i.e 3.14 * radius * radius

Solution:
#include<iostream>
using namespace std;
int main()
{

int r, a;
cout<<"please put radius of circle =";
cin>>r;
a=(3.14*r*r);
cout<<" area of circle = "<<a;
return 0;

}
Program # 5: Write a C++ program to prompt the user to input 3 integer values and print these
values in forward and reversed order, as shown below.
Please enter first numbers: 12
Please enter first numbers: 45
Please enter first numbers: 78
Your numbers forward:
12
45
78
Your numbers reversed:

78

45

12
Solution:

#include <cstdlib>
#include <iostream>

using namespace std;

int main()
{
int val1;
int val2;
int val3;
cout<<"Please enter your 1st numbers:";
cin>>val1;
cout<<"Please enter your 2nd numbers:";
cin>>val2;
cout<<"Please enter your 3rd numbers:";
cin>>val3;

cout<<"\nYour numbers forward:\n";


cout<<val1<<endl;
cout<<val2<<endl;
cout<<val3<<endl;
cout<<" "<<endl;
cout<< "Your numbers reversed:\n";
cout<<val3<<endl;
cout<<val2<<endl;
cout<<val1;

return 0;
}
Program # 6: Get a number from the user on runtime and display that number and its square.
Solution:
#include<iostream>
using namespace std;
int main()
{
int a, b;
cout<<"Put your number there square required = ";
cin>>a;
cout<<"____________________________"<<endl;
cout<<"Square of your nuber "<<a<<"^2="<<(a*a);
return 0;
}

Program # 7: Make a program which will get a Total Bill from user and display a message 10 %

Discount allowed if Total Bill is greater than 20000.

#include <stdio.h>
int main(void)
{

double quantity,price,amount,discount;
printf("Enter Quantity and Price:");
scanf("%lf %lf",&quantity, &price);

amount=quantity*price;

if(amount>5000)

discount=amount*0.10;
amount=amount-discount;

printf("%lf",amount);
return 0;

}
Program#08 Write a program in C++ that takes a number as input and prints its multiplication
Table.

Sample Output:

Enter a number: 5

5x1=5
5 x 2 = 10
5 x 3 = 15
5 x 4 = 20
5 x 5 = 25
5 x 6 = 30
5 x 7 = 35
5 x 8 = 40
5 x 9 = 45
5 x 10 = 50

Solution;
#include<iostream>
Using namespace std;
Int main()
{

Int a;
Cout<<”please put your number there multiplication table needed =”;
Cin>>a;

Cout<<a<<”x1 = “<<a*1<<endl;
Cout<<a<<”x2 = “<<a*2<<endl;
Cout<<a<<”x3 = “<<a*3<<endl;
Cout<<a<<”x4 = “<<a*4<<endl;
Cout<<a<<”x5 = “<<a*5<<endl;
Cout<<a<<”x6 = “<<a*6<<endl;
Cout<<a<<”x7 = “<<a*7<<endl;
Cout<<a<<”x8 = “<<a*8<<endl;
Cout<<a<<”x9 = “<<a*9<<endl;
Cout<<a<<”x10 = “<<a*10<<endl;

Return 0;

}
Program # 10: Get input for two integers from the user and swap their value and display as

Following
Before swaping
First number : 23
Second number : 90
After swaping
First number : 90
Second number : 23

Solution:

#include<iostream>
Using namespace std;
Int main()
{

Int a, b;
Cout<<” first number = “;
Cin>>a;
Cout<<” second number = “;
Cin>>b;
Cout<<” “<<endl;
Cout<<” after swap “<<endl;
Cout<<” first number = “<<b<<endl;
Cout<<” second number= “<<a;
Return 0;

You might also like