Sei sulla pagina 1di 9

Introduction to Computing

Assignment 3

Session: SPRING 2013

Faculty of Information Technology UCP Lahore Pakistan

Question 1
Write program for the following problems. 1. Prompt and Input three numbers from the user and find their average. Expected output: #include<iostream.h> void main() { int a,b,c,avg; cout<<"Enter 1st Number: "; cin>>a; cout<<"Enter 2nd Number: "; cin>>b; cout<<"Enter 3rd Number: "; cin>>c; avg=(a+b+c)/3; cout<<"Average of Numbers is = "<<avg <<endl;

} Enter the first number: 20 Enter the second number: 30 Enter the third number: 20 Average = 23

Question 2
(Diameter, Circumference and Area of a Circle) Write a program that reads in the radius of a circle and prints the circles diameter, circumference and area. Use the constant value 3.14159 for . Expected output: Enter the radius: Diameter= 50 Circumference = 159.0795 Area= 1963.49375 25

#include<iostream.h> void main() { double rad,circum,dia,area; cout<<"Enter Radius of Circle: "; cin>>rad; area=3.14*rad*rad; circum=2*rad*3.14; dia=2*rad; cout<<"Area of Circle = " <<area <<endl; cout<<"Circumference of Circle = " <<circum <<endl; cout<<"Diameter of Circle = " <<dia;

Question 3
Write program for following problems: Ask the user to enter two numbers, obtain them from the user and prints their sum, product, difference, quotient and remainder. Expected output: #include<iostream.h> void main() { int num1,num2,add,sub,mul,quo,mod; cout<<"Enter 1st Number: ";

cin>>num1; cout<<"Enter 2nd Number: "; cin>>num2; add=num1+num2; sub=num1-num2; mul=num1*num2; quo=num1/num2; mod=num1%num2;

cout<<"Addition = " <<add <<endl; cout<<"Difference = " <<sub <<endl; cout<<"Multiplication = " <<mul <<endl; cout<<"Quotient = " <<quo <<endl; cout<<"Remainder = " <<mod <<endl; } Enter the First number: Enter the second number: Sum = 90 Product= 900 Difference = 50 Quotient = 3 Remainder = 10 70 20

Question 4
Take a number a and a number b and swap their values.

Hint: Use a temporary variable to store the value. Expected Output: Enter Number 1: 15 Enter Nember 2: 59 Values after swapping are Number 1 = 59 Number 2 = 15

#include<iostream.h> void main() { int num1,num2,temp; cout<<"Enter 1st Number: "; cin>>num1; cout<<"Enter 2nd Number: "; cin>>num2; cout<<"Values Before Swaping: "<<num1 <<" "<<num2 <<endl; temp=num1; num1=num2; num2=temp; cout<<"Values After Swaping: " <<num1 <<" "<<num2 <<endl; }

Question 4

Draw flow chart that read temperature in Fahrenheit and convert that into Celsius and Kelvin.

#include<iostream.h> void main() { double farh,cel,kel; cout<<"Enter Temprature in Farenheit = "; cin>>farh; cel=(0.555)*(farh-32); kel=cel+273; cout<<"Temprature in Celcius = " <<cel <<endl; cout<<"Temprature in Kelvin = " <<kel <<endl; }

Question 5
Draw flow chart of a problem that takes measurement in meters and convert into centimeter, millimeter, Kilometer and feet using the following conversion table 1Kilo meter = 1000 meter 100 centimeters = 1 meter 1000 millimeters = 1 meter 1 meter = 3.28 feet /*1Kilo meter = 1000 meter 100 centimeters = 1 meter 1000 millimeters = 1 meter 1 meter = 3.28 feet

*/ #include<iostream.h> void main() { float meters,mm,cm,km,feet; cout<<"Enter Meters = "; cin>>meters; cout<<endl; km=meters/1000; cm=meters*100; mm=meters*1000; feet=meters*3.28; cout<<"Kilometers = "<<km<<endl; cout<<"Centimeters = "<<cm<<endl; cout<<"Millimeters = "<<mm<<endl; cout<<"Feet = "<<feet<<endl; }

Question 6
Find the value of A such that the value of a, b and c will be input by the user. A = (a - b)2 / 2c

#include<iostream.h> void main() { float a,b,c,A; cout<<"Enter Value of a: "; cin>>a; cout<<"Enter Value of b: "; cin>>b; cout<<"Enter Value of c: "; cin>>c; A=((a - b)*(a - b)) / (2*c); cout<<"Value of A = " <<A<<endl; }

Question 7
Write an algorithm that reads the amount of change (currency notes) and finds the minimum number of bills represented by the change. Assume that the bills available are 1, 5, 10, and 20 Rupees.

Potrebbero piacerti anche