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

LAB CP Assignment 3

This document contains 9 programming assignments completed by a student for their Computer Programming course. Each assignment involves writing C++ code to solve problems related to converting units of measurement, calculating values like volume, averages, and temperatures. The assignments increase in complexity and cover topics like loops, functions, user input/output. For each task, the student provides the algorithm/pseudocode, C++ code, and output for the programs.

Uploaded by

Abuzar Sheikh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
78 views

LAB CP Assignment 3

This document contains 9 programming assignments completed by a student for their Computer Programming course. Each assignment involves writing C++ code to solve problems related to converting units of measurement, calculating values like volume, averages, and temperatures. The assignments increase in complexity and cover topics like loops, functions, user input/output. For each task, the student provides the algorithm/pseudocode, C++ code, and output for the programs.

Uploaded by

Abuzar Sheikh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

University of

Engineering Technology &

Taxila

2020

[Computer Programming]

Department of Computer Engineering

Assignment No 3

SUBMITTED BY:
SHEIKH ABUZAR AMJAD
REG NO:
19-CP-6
SUBMITTED TO:
SIR SHEHRYAR KHAN
Task No 01:-
Write a program in C++ to get the age of the person. The program
should calculate and the display the age of the person in months.
OR
Write a program in C++ that input your age in years. Convert that
age in months, day’s hour’s minutes and seconds and then print
all these values on the screen.
CODE
#include <iostream>

#include <cstdlib>

using namespace std;

int main()

int y,m,d,hrs,min,sec;

cout<<"Enter Age in Years:";

cin>>y;

m = y*12;

cout<<"Your Age in months:"<<m<<endl;

d = y*365;

cout<<"Your Age in days:"<<d<<endl;

hrs = y*8760;

cout<<"Your Age in Hours:"<<hrs<<endl;

min = y*525600;

cout<<"Your Age in Minutes:"<<min<<endl;

sec = y*31536000;

cout<<"Your Age in Seconds:"<<sec<<endl;

return 0;

1|Page
OUTPUT

Task No 02:-
Write a program that convert the length given in feet and inches
into centimeters using the formula 1 inch=2.54 cm. Display the
result on the screen.
CODE
#include <iostream>
using namespace std;
int main()
{
float ft,inch,cm,totalInches;
cout<<"Enter length in Feets:";
cin>>ft;
cout<<"Enter Inches:";
cin>>inch;
totalInches = 12*ft+inch;
cout<<"Total length in inches are:"<<totalInches<<endl;
cm = 2.54*totalInches;
cout<<"length in Centimeters:"<<cm<<endl;
return 0;
}
OUTPUT

2|Page
Task No 03:-
Write a program that produces the following output:

Algorithm
#include<iostream>

using namespace std;

int main()

for(int i=41;i>=1;i--)

cout<<"*";

3|Page
}

cout<<"\n*\tProgramming Assignment 1\t*"<<endl;

cout<<"*\tComputer Programming I\t\t*"<<endl;

cout<<"*\t\tAuthor: ???\t\t*"<<endl;

cout<<"* Due Date: Thursday, Jan. 24\t*"<<endl;

for(int i=41;i>=1;i--)

cout<<"*";

return 0;

}
OUTPUT

Task No 04:-
Write a program that produces the following output:

4|Page
ALGORITHM
#include<iostream>
using namespace std;
int main()
{
cout<<"CCCCCCCCCCC\t\t++\t\t\t\t++"<<endl;
cout<<"CC\t\t\t++\t\t\t\t++"<<endl;
cout<<"CC\t\t+++++++++++++++++\t\t+++++++++++++++++"<<endl;
cout<<"CC\t\t+++++++++++++++++\t\t+++++++++++++++++"<<endl;
cout<<"CC\t\t\t++\t\t\t\t++"<<endl;
cout<<"CCCCCCCCCCC\t\t++\t\t\t\t++"<<endl;
}
OUTPUT

Task No 05:-
Write a program in C++ to get the marks of the students
in three subjects Programming Fundamental, Digital
Logic Design and Circuit Analysis. Calculate the total
and average marks. Each subject has a maximum of 100
marks.
ALGORITHM
#include <iostream>
using namespace std;
int main()
{
5|Page
int x,y,z;
float avg;
int totalMarks;
cout<<"Enter marks of Programming Fundamental:";
cin>>x;
cout<<"Enter marks of DLD:";
cin>>y;
cout<<"Enter marks of Crircuit Analysis:";
cin>>z;
totalMarks=x+y+z;
cout<<"Total Marks:"<<totalMarks<<endl;
avg = totalMarks/3;
cout<<"Average marks of Student:"<<avg<<endl;
return 0;
}
OUTPUT

6|Page
Task No 06:-
Write a program in C++ to compute and print the
volume of a cylinder where “r” is the radius and “h” is
the height and these values are provided by the user at
runtime. (vol=πhr2 and π=3.14).
ALGORITHM
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
int r,h;
float pi,vol;
pi=3.14;
cout<<"Enter radius of cylinder r =";
cin>>r;
cout<<"Enter height of cylinder h =";
cin>>h;
vol = pi*r*r*h;
cout<<"Volume of Cylinder is:"<<vol<<endl;
return 0;
}
OUTPUT

7|Page
Task No 06:-
Write a program in C++ to read temperature in
Fahrenheit. Convert the temperature to Celsius degrees
by using the formula.
𝒄=𝟓/𝟗(𝒇−𝟑𝟐)
ALGORITHM
#include <iostream>
using namespace std;
int main()
{
int F,C;
cout<<"Enter Temprature in Fahernheit:";
cin>>F;
C = 5*(F-32)/9;
cout<<"Temprature in Celcius:"<<C<<endl;
return 0;
}
OUTPUT

8|Page
THE end

9|Page

You might also like