You are on page 1of 17

SUKKUR INSTITUTE OF BUSINESS ADMINISTRATION

INTRODUCTION TO PROGRAMMING #-LAB

MANUAL-#

NAME: RAHMAN ALI


CLASS: BS-II
DEPARTMENT: -COMPUTER SCIENCE

INSTRUCTOR: ENGINEER NAHDIA MAJEED

1 BS-CS---DEPARTMENT OF COMPUTER SCIENCE


SUKKUR INSTITUTE OF BUSINESS ADMINISTRATION

INTRODUCTION TO PROGRAMMING #-LAB

MANUAL-#

LAB-01
Q-1;
#include<iostream>
using namespace std;
#include<conio.h>
{
int main()
// (A) using one statement with one stream insertion
operator.
cout<<"1\t2\t3\t4\t5\t6\n";

//(B)using N statements
cout<<"\t1";

cout<<"\t2";

cout<<"\t3";

cout<<"\t4";

cout<<"\t5";

cout<<"\t6";

cout<<"\t7\n";

//(C)using one statement with N stream insertion operator.


cout<<"\t1"<<"\t2"<<"\t3"<<"\t4"<<"\t5"<<"\t6"<<"\t7\n";

getch();

return o;
}

Q-2:
2 BS-CS---DEPARTMENT OF COMPUTER SCIENCE
SUKKUR INSTITUTE OF BUSINESS ADMINISTRATION

INTRODUCTION TO PROGRAMMING #-LAB

MANUAL-#

#include<iostream>
using namespace std;
#include<conio.h>
{

int main()

cout<<"Candy is dandy,\nBut liquor is quicker.";

getch();

return 0;
}

Q-3:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
cout<<"\n********** * *";
cout<<"\n* * *** * * ";
cout<<"\n* * ***** * * ";
cout<<"\n* * * * *";
cout<<"\n* * * * * ";
cout<<"\n* * * * * ";
cout<<"\n* * * * * ";
cout<<"\n* * * * * " ;
cout<<"\n* * * * * " ;
cout<<"\n********** * * ";
getch();}

LAB-2
3 BS-CS---DEPARTMENT OF COMPUTER SCIENCE
SUKKUR INSTITUTE OF BUSINESS ADMINISTRATION

INTRODUCTION TO PROGRAMMING #-LAB

MANUAL-#

Q-1:
#include<iostream>
#include<conio.h>
using namespace std;

int main()
{
int a,b,c,d,sum,r;
cout<<"enter numerator for 1st fraction:";
cin>>a;
cout<<"enter denominator for 1st fraction:";
cin>>b;
cout<<"enter numerator for 2nd fraction:";
cin>>c;
cout<<"enter denominator for 2nd fraction:";
cin>>d;
sum=(a*d)+(b*c);
r=b*d;
cout<<"sum is:"<<sum<<" / "<<r;

getch();
return 0;
}

Q-2:
#include<conio.h>
using namespace std;
#include<iostream>
void main()
{
Int t;
cout<<”enter number for table=”;
cin>>t;
cout<<”table of”<<t<<”\n”;
cout<<t<<”*1=\t”<<t*1<<”\n”;
cout<<t<<”*2=\t”<<t*2<<”\n”;
cout<<t<<”*3=\t”<<t*3<<”\n”;
cout<<t<<”*4=\t”<<t*4<<”\n”;

4 BS-CS---DEPARTMENT OF COMPUTER SCIENCE


SUKKUR INSTITUTE OF BUSINESS ADMINISTRATION

INTRODUCTION TO PROGRAMMING #-LAB

MANUAL-#

cout<<t<<”*5=\t”<<t*5<<”\n”;
cout<<t<<”*6=\t”<<t*6<<”\n”;
cout<<t<<”*7=\t”<<t*7<<”\n”;
cout<<t<<”*8=\t”<<t*8<<”\n”;
cout<<t<<”*9=\t”<<t*9<<”\n”;
cout<<t<<”*10=\t”<<t*10<<”\n”;

getch();
}

Q----3:

#include<iostream>
using namespace std;
#include<conio.h>
void main()
{
int d,n;
cout<<"enter deviser:";

cin>>d;

cout<<"enter an integer:";

cin>>n;

if(n%d==0)

cout<<d<<"is a divisor of"<<n;

5 BS-CS---DEPARTMENT OF COMPUTER SCIENCE


SUKKUR INSTITUTE OF BUSINESS ADMINISTRATION

INTRODUCTION TO PROGRAMMING #-LAB

MANUAL-#

else

cout<<d<<"is not adivisor of"<<n;

LAB—3
Q---1:
6 BS-CS---DEPARTMENT OF COMPUTER SCIENCE
SUKKUR INSTITUTE OF BUSINESS ADMINISTRATION

INTRODUCTION TO PROGRAMMING #-LAB

MANUAL-#

#include<iostream.h>//perform the input output headre function


#include<conio.h>
void main()//function calling
{
clrscr();
int x,h,y,k,m;//declare variables

cout<<"enter the value of x:";//prompt user to input the


value of x

cin>>x;//takes input from user

cout<<"enter the value of h:";//prompt user to input the


value of h

cin>>h;//takes input from user

cout<<"enter the value of y:";//prompt user to input the


value of y

cin>>y;//takes input from user

cout<<"enter the value of k:";//prompt user to input the


value of k

cin>>k;//takes input from user

m=(x-h)*(x-h)+(y-k)*(y-k);//makes the sum of integers

cout<<"value of m is="<<m;//display the result

getch();//get character on screen


}

Q---2:

#include<iostream.h>

7 BS-CS---DEPARTMENT OF COMPUTER SCIENCE


SUKKUR INSTITUTE OF BUSINESS ADMINISTRATION

INTRODUCTION TO PROGRAMMING #-LAB

MANUAL-#

#include<conio.h>
void main()
{
clrscr();

int x,y;
cout<<"enter the value of x:";

cin>>x;

cout<<"enter the value of y:";

cin>>y;

if(x==y)//checks the conditon

cout<<"x is equal to y";//print if condion is true

else
if(x!=y)//checks an other condition

cout<<"x is not equal to y";//print if condion is true

else

if(x>y) //checks an other condition

cout<<"x is smaller to y";//print if condion is true

else
if(x<y) //checks an other condition

cout<<"x is grater to y";//print if condion is true

else //print if condition is false


cout<<"Erroe,choice was not valid,here is your money back"

getch();

8 BS-CS---DEPARTMENT OF COMPUTER SCIENCE


SUKKUR INSTITUTE OF BUSINESS ADMINISTRATION

INTRODUCTION TO PROGRAMMING #-LAB

MANUAL-#

Q---3;
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();

int number;//declare variable

cout<<"Enter(1-5) from menu :";


//print message under inverted commas

cout<<"1-Apple juice:\n"; //print message under inverted


commas

cout<<"2-Mango juice:\n"; //print message under inverted


commas

cout<<"3-sprite\n"; //print message under inverted commas

cout<<"4-tea\n"; //print message under inverted commas

cout<<"5-watre"; //print message under inverted commas

cin>>number; //takes the input from user

if(number==1) //checks the condition

cout<<"Apple juice:"; //print if true

if(number==2) //checks the condition

9 BS-CS---DEPARTMENT OF COMPUTER SCIENCE


SUKKUR INSTITUTE OF BUSINESS ADMINISTRATION

INTRODUCTION TO PROGRAMMING #-LAB

MANUAL-#

cout<<"Mango juice:"; //print if true

if(number==3) //checks the condition

cout<<"sprite:"; //print if true

if(number==4) //checks the condition

cout<<"tea:"; //print if true

if(number==5) //checks the condition

cout<<"water:"; //print if true

if(number>5) //checks the condition

cout<<"error choice was not valid"; //print if false all


conditions
getch(); }
Q---4:
#include<iostream.h>//perform inpur output function
#include<conio.h>
void main()//funtion calling
{
clrscr();//clear screen
int marks;//declare variable
cout<<"Enter the marks scored in programming:";
//prompt user to input the mark
cin>>marks;//takes marks from user

if(marks>90)//checks condition

cout<<"you scored an A";//print if true,

if(marks==100)//checks condition

cout<<"you got a perfect score:";//print if true

10 BS-CS---DEPARTMENT OF COMPUTER SCIENCE


SUKKUR INSTITUTE OF BUSINESS ADMINISTRATION

INTRODUCTION TO PROGRAMMING #-LAB

MANUAL-#

if(marks<90)//checks condition

cout<<"better luck next time:";//print if condition is true

getch();//get character
} //end of program

LAB---4
Q-1:-
11 BS-CS---DEPARTMENT OF COMPUTER SCIENCE
SUKKUR INSTITUTE OF BUSINESS ADMINISTRATION

INTRODUCTION TO PROGRAMMING #-LAB

MANUAL-#

//This program is made by Rahman Ali from BS-2(Computer Science)


THP

#include<iostream> //use for input and output


using namespace std;
#include <conio.h>

int main() // the main function


{
system("color b");

int fac,pre; // Integer type variables which stores values

cout<<"\nEnter Value for Factor: "; //Prompt user to input


Value

cin>>fac;

if(fac<=10) //checks Conditon


{
cout<<"\nValue of Pressure is "<<(pre=35); // print 35 for
above conditon
}

Else
if(fac>=11) //cecks condition
if(fac<=15) //This statment verify that factor value is less
than or equal to 15
{
cout<<"\nValue of Pressure is "<<(pre=45); //It will print
45 for values between 11 to 15
}

else if(fac>=16) //condition that if factor value is


greater than if(fac<=19) //This statment verify that
factor value is less than or equal to 19
{

12 BS-CS---DEPARTMENT OF COMPUTER SCIENCE


SUKKUR INSTITUTE OF BUSINESS ADMINISTRATION

INTRODUCTION TO PROGRAMMING #-LAB

MANUAL-#

cout<<"\nValue of Pressure is "<<(pre=55); //It will print


55 for values between 16 to 19
}

if(fac==20) //This condition checks factor value is whether


20 or not
{
cout<<"\nValue of Pressure is "<<(pre=60); //It will print
60 for factor value of 20
}

else
if (fac>20) //Its an condition that if other Values Enters
as value of factor those are greater than 20
{

Q-2:-
//This program is made by RAHMAN ALI from BS-2(Computer Science)
THP

#include<iostream> // use for giving input and getting output


using namespace std;
#include <conio.h> //is a C header file used in old MS-DOS
compilers to create text user interfaces
{

int main() //It is the main function


double earn,er,red,rop,res,p; //declare float type variables
which stores decimal values

cout<<"\nEnter Earnings of Salesman in a Week: "; //Promt


user to input Total earnings

cin>>earn;//takes input from user

13 BS-CS---DEPARTMENT OF COMPUTER SCIENCE


SUKKUR INSTITUTE OF BUSINESS ADMINISTRATION

INTRODUCTION TO PROGRAMMING #-LAB

MANUAL-#

if(earn<3000)//ckecks condition whether earning is greater


then 3000
{
er=earn+200; //Addition of 200 in your total earning

cout<<"\nYour Price is "<<earn<<"\n n u got only 200 Extra


and no bonus: "<<er;
}
if(earn>=3000) //ckecks Conditon
{

red=0.09; //Profit percentage which is 9 Percent on sale

rop=earn*0.09; //This will the total profit on your Price

cout<<"\n\n\n\nYour 9% profit on Total income is: "<<rop;


//Its total Profit

res=rop+200; //Now 200 add in your Profit

cout<<"\n\n200 Are added in your Profit and \nTotal profit


is: "<<res<<"\n"; //Its Grand profit with addition of 200

p=res+earn;
cout<<"tour total earning per week is"<<p;
}

getch();
return 0; }

LAB---5

14 BS-CS---DEPARTMENT OF COMPUTER SCIENCE


SUKKUR INSTITUTE OF BUSINESS ADMINISTRATION

INTRODUCTION TO PROGRAMMING #-LAB

MANUAL-#

Q-1:
/* this program is created by RAHMAN ALI for finding the size of
variable which it consumes in the memory*/

#include<conio.h>
#include<iostream.h>
void main() // main function calling
{ // start of program
int a; // declaration of variable
cout<<sizeof(a); // finding the size of varible by using
size of.

getch(); // getch command to hold the result screen


}

Q—2:-
#include<conio.h>
#include<iostream.h>
void main ()
{
clrscr();
int a=2,b=3, result;//declare variables
float x=3.0,y;
y=a*b;//perform the operation of multiplication
cout<<"\n "<<y;//display result in integer

result=a*b;
cout<<"\n "<<result;//display result in integer

y=a/b;
cout<<"\n "<<y;//display result in integer
15 BS-CS---DEPARTMENT OF COMPUTER SCIENCE
SUKKUR INSTITUTE OF BUSINESS ADMINISTRATION

INTRODUCTION TO PROGRAMMING #-LAB

MANUAL-#

y=a/b*x;
cout<<"\n "<<y;//display result in integer

y=a*x/b;
cout<<"\n "<<y;//display result in integer
result=a*x/b
cout<<"\n"<<result;//display result in integer

getch();
}

Q—3:
#include<iostream>
using namespace std;
#include<conio.h>

int main() //It is the main function

{
system("color b");

float hr,min; //These are the Float type variables which


stored decimal values
cout<<"****Welcome To Hours into Minutes
conversion****\n\nEnter Hours: "; //Prmpt user to input
Hours
cin>>hr; //Taking input from the user
if (hr>0)//puts condition for wrong input

{
min=hr*60;//because 1 hour is equal to 60 min

cout<<"\n"<<hr<<" Hours are equal to "<<min<<" Minutes";

else

16 BS-CS---DEPARTMENT OF COMPUTER SCIENCE


SUKKUR INSTITUTE OF BUSINESS ADMINISTRATION

INTRODUCTION TO PROGRAMMING #-LAB

MANUAL-#

cout<<"\nError. Wrong Entry";//print if user input wrong


entry
getch();
return 0;
}

Q---4:-
#include<conio.h>
#include<iostream.h>
void main()
{
clrscr();
float gallon;//declare variable
cout<<"enter the value in gallon:";//prompt user to enter
gallons
cin>> gallon;//takes input from user
cout<<gallon<<"gallons are equal to"<<gallon*7.481<<"cubic
feet";//display result
getch();
}

17 BS-CS---DEPARTMENT OF COMPUTER SCIENCE

You might also like