SlideShare a Scribd company logo
C++ practical lab
Programming whit C++
TABLE OF CONTENTSTABLE OF CONTENTSTABLE OF CONTENTSTABLE OF CONTENTS
Page No
Submitted to: Mr.Kamran Khan
Submitted by: Padshah Gul
Course: Bs-Telecom
1. WRITE A PROGRAM TO SHOW YOUR DESIRE TEXT ON SCREEN:…………………………………………………………………… 1
2. FINDING VELOCITY OF DRAM ( ∏∏∏∏R2
.H): ……………………………………………………………………………………………………….. 1
3. USING SOME ARITHMETIC OPERATIONS:……………………………………………………………………………………………………… 2
4. TEMPERATURE CALCULATION:……………………………………………………………………………………………………………………… 3
CONVERT CELSIUS TO FAHRENHEIT: .......................................................................................................................................3
CONVERT FAHRENHEIT TO CELSIUS: .......................................................................................................................................3
WRITE A PROGRAM TO CALCULATE THE TOTAL MARKS, AVERAGE & PERCENTAGE OF 10TH DIFFERENT SUBJECTS:...............................4
CREATING DESIGN OF ATM MACHINE DISPLAY IN C++:............................................................................................................5
TIME CONVERTER:..............................................................................................................................................................6
LENGTH CONVERTER:..........................................................................................................................................................6
WRITE A PROGRAM TO CALCULATE AVERAGE AGE OF A CLASS OF 10TH STUDENTS: .........................................................................8
5. INCREMENT:………………………………………………………………………………………………………………………………………………... 9
PREFIX (++I): ....................................................................................................................................................................9
POSTFIX (I++): ................................................................................................................................................................10
6. DECREMENT:………………………………………………………………………………………………………………………………………………… 11
PREFIX (--I):....................................................................................................................................................................11
POSTFIX (I--):..................................................................................................................................................................11
7. CONDITION STATEMENTS:……………………………………………………………………………………………………………………………. 13
IF CONDITION:.............................................................................................................................................................13
IF CONDITION:.............................................................................................................................................................13
IF CONDITION:.............................................................................................................................................................14
IF-ELSE: .........................................................................................................................................................................14
IF-ELSE: .........................................................................................................................................................................15
WRITE A PROGRAM TO CHECK WITHER THE GIVEN NUMBER IS ODD OR EVEN. ............................................................................16
USING (IF-ELSE) ...............................................................................................................................................................16
WRITE A PROGRAM TO CHECK A PERSON IS MALE OR FEMALE BY INPUT CHARACTER.......................................................................16
USING (IF-ELSE):..............................................................................................................................................................16
WRITE A PROGRAM TO CHECK POSITIVE NUMBER AND NEGATIVE NUMBER...................................................................................17
USING (IF-ELSE):..............................................................................................................................................................17
NESTED IF ELSE:...............................................................................................................................................................18
USING OF SIMPLE ARITHMETIC OPERATORS (USING IF ELSE): .....................................................................................................19
A PROGRAM IN WHICH MAKERS OBTAINED IN ANY SUBJECT INPUT THROUGH KEYBOARD .................................................................20
CALCULATE TOTAL, PERCENTAGE AND AVERAGE USE LOGICAL OPERATORS: .................................................................................20
8. SWITCH STATEMENT:…………………………………………………………………………………………………………………………………… 21
-- :( SPORTS REGISTRATION MENU ): --........................................................................................................................21
9. LOOPS:………………………………………………………………………………………………………………………………………………………… 26
WRITE A PROGRAM TO PRINT FIVE TIMES “I LOVE PAKISTAN" (USING WHILE LOOP):....................................................................26
WRITE A PROGRAM TO PRINT NATURAL NUMBER FROM 1 TO 100 IN ASCENDING FORM BY (USING WHILE LOOP):..........................26
WRITE A PROGRAM TO PRINT NATURAL NUMBER FROM 10 TO 1 IN DESCENDING FORM BY (USING WHILE LOOP): ...........................27
Programming whit C++
TABLE OF CONTENTSTABLE OF CONTENTSTABLE OF CONTENTSTABLE OF CONTENTS
Page No
Submitted to: Mr.Kamran Khan
Submitted by: Padshah Gul
Course: Bs-Telecom
WRITE A PROGRAM TO PRINT FIRST EVEN NUMBER FROM 1 TO 100 BY (USING WHILE LOOP):.....................................................28
WRITE A PROGRAM TO PRINT FIRST ODD NUMBER FROM 1 TO 100 BY (USING WHILE LOOP):.......................................................28
WRITE A PROGRAM TO FIND THE SUM OF FOLLOWING SERIES BY (USING WHILE LOOP).................................................................29
USING DO-WHILE LOOP: ....................................................................................................................................................29
WRITE A PROGRAM TO PRINT NATURAL NUMBER FROM 1 TO 10 AND SUM IT BY...........................................................................30
(USING DO-WHILE LOOP):..................................................................................................................................................30
WRITE A PROGRAM TO PRINT TABLE OF TWO BY (USING FOR LOOP): ..........................................................................................31
WRITE A PROGRAM TO PRINT TABLE OF ANY NUMBER BY (USING FOR LOOP):...............................................................................32
NATURAL NUMBER FROM (1 TO 10 AND FORM 10 TO 1) BY (USING FOR LOOP):....................................................................32
NESTED LOOPS:...............................................................................................................................................................33
10. ARRAY:………………………………………………………………………………………………………………………………………………………… 34
WRITE A PROGRAM IN ARRAY TO PRINT FIXED NUMBER FROM INPUT:.........................................................................................34
WRITE A PROGRAM IN ARRAY TO PRINT VARIABLE NUMBER (USER CHOICE) CALCULATE SUM AND AVERAGE:.....................................34
WRITE A PROGRAM IN ARRAY TO ENTER VALUE AND THEN PRINT VALUE IN REVERSE ORDER...........................................................35
WRITE A PROGRAM TO FIND OUT AND PRINT THE MAXIMUM VALUE IN THE ARRAY: ......................................................................36
WRITE A PROGRAM TO FIND OUT AND PRINT THE MINIMUM VALUE IN THE ARRAY:.......................................................................37
WRITE A PROGRAM IN A CHARACTER TYPE ARRAY TO COPY "FIRST" ARRAY INTO "SECOND" ARRAYS:................................................37
WRITE A PROGRAM TO INPUT DATA INTO TWO DIFFERENT ARRAYS AND THEN SUM INTO A THIRD ARRAY............................................38
STRING VARIABLE (NULL CHARACTER)..................................................................................................................................39
WRITE A PROGRAM IN A STRING TYPE ARRAY TO COPY "FIRST" ARRAY INTO "SECOND" ARRAYS:......................................................39
TWO DIMENSION ARRAY:..................................................................................................................................................40
WRITE A PROGRAM TO PRINT THE OUTPUT OF FOLLOWING TABLE. .............................................................................................40
WRITE A PROGRAM TO PRINT TABLE OF 4X5(4 ROWS & 5 COLUMNS). .......................................................................................41
11. STRUCTURES:……………………………………………………………………………………………………………………………………………….. 42
WRITE A PROGRAM TO INPUT DATA INTO AND THEN PRINT DATA FROM THE MEMBERS OF STRUCTURE: .............................................42
WRITE A PROGRAM TO DEFINE A STRUCTURE WITH FIVE MEMBERS. THE FIRST MEMBER BE STUDENT NAME AND THE OTHER BE OBTAINED
MARKS IN FOUR SUBJECTS. .................................................................................................................................................43
WRITE A PROGRAM TO INPUT DATA IN STRUCTURE AND THEN TO FIND OUT THE SUM OF MARKS. STORE THE RESULT IN THE MEMBER
“TOTAL” PRINT THE DATA ON THE SCREEN. ............................................................................................................................44
12. FUNCTION:………………………………………………………………….……………………………………………………………..……………….. 46
WRITE A PROGRAM TO PRINT A MESSAGE ON THE SCREEN USING A FUNCTION.............................................................................46
WRITE A PROGRAM TO PASS THREE VARIABLES AS PARAMETERS FROM INPUT TO THE FUNCTION TO CALCULATE THEIR SUM...................46
WRITE A PROGRAM TO PASS THREE VARIABLES AS PARAMETERS FROM USER TO THE FUNCTION TO CALCULATE THEIR SUM....................47
WRITE A PROGRAM TO PRINT A TABLE OF A GIVEN NUMBER USING FUNCTION..............................................................................48
WRITE A PROGRAM FOR CALCULATOR BY PASSING THREE ARGUMENTS TO THE FUNCTION. .............................................................49
1ST AND 3RD ARE NUMERIC NUMBERS AND 2ND IS ARITHMETIC OPERATORS...............................................................................49
WRITE A PROGRAM TO FIND THE MAXIMUM NUMBER FROM AN ARRAY BY USING THE FUNCTION.....................................................50
LOCAL VARIABLES IN FUNCTION: .........................................................................................................................................51
GLOBAL VARIABLES IN FUNCTION:.......................................................................................................................................52
Chapter: 1Chapter: 1Chapter: 1Chapter: 1
Programming whit C++
---------------------------------------------------------------------------------------------------------------------------------------------------------
Submitted to: Mr.Kamran Khan
Submitted by: Padshah Gul
Course: Bs-Telecom Page No: - 1 of 52
Write a program to show your Desire text on screen:
#include <iostream.h>
#include <conio.h>
void main (void)
{
clrscr();
cout<<"My name is Padshah Gul."<<endl;
cout<<"I am student of Sarhad University."<<endl;
cout<<"I am from Afghanistan."<<endl;
getch();
}
Output of Program:
My name is Padshah Gul.
I am student of Sarhad University.
I am from Afghanistan.
Finding velocity of dram ( ∏∏∏∏r2.h):
#include <iostream.h>
#include <conio.h>
void main (void)
{
clrscr();
float h=8;
float r=5;
float pi=3.14;
float v=h*r*r*pi;
cout<<"Result is "<<v;
getch();
Height= 8 cm
2r=10 cm
Chapter: 1Chapter: 1Chapter: 1Chapter: 1
Programming whit C++
---------------------------------------------------------------------------------------------------------------------------------------------------------
Submitted to: Mr.Kamran Khan
Submitted by: Padshah Gul
Course: Bs-Telecom Page No: - 2 of 52
}
Using some arithmetic operations:
Like ( +, -, *, /, %)
#include <iostream.h>
#include <conio.h>
void main (void)
{
clrscr();
int p,s,m,d,r;
p=7+5;
s=10-3;
m=4*2;
d=10/2;
r=11%5;
cout<<"output of arithmetic operators"<<endl;
cout<<endl<<"Addition of 8 and 2 is = "<<p<<endl;
cout<<"Subtraction of 10 and 3 is = "<<s<<endl;
cout<<"Multiplication of 4 and 2 is = "<<m<<endl;
cout<<"Division of 10 and 2 is = "<<d<<endl;
cout<<"Remainder of 5/2 is = "<<r<<endl;
getch();
}
Output of the program:
Addition of 8 and 2 is = 10
Subtraction of 10 and 3 is = 7
Multiplication of 4 and 2 is = 8
Division of 10 and 2 is = 5
Chapter: 1Chapter: 1Chapter: 1Chapter: 1
Programming whit C++
---------------------------------------------------------------------------------------------------------------------------------------------------------
Submitted to: Mr.Kamran Khan
Submitted by: Padshah Gul
Course: Bs-Telecom Page No: - 3 of 52
Remainder of 5/2 is = 1
Temperature Calculation:
Convert Celsius to Fahrenheit:
Convert Fahrenheit to Celsius:
#include <iostream.h>
#include <conio.h>
void main(void)
{
clrscr();
cout<<endl<<endl<<"ttt Temperature Calculation"<<endl;
cout<<"ttt"<<endl;
cout<<endl<<endl<<"t0-------------0"<<endl;
cout<<"tl Well Come!! l"<<endl;
cout<<"t0-------------0"<<endl;
cout<<endl<<endl<<"tconvert Fahrenheit to Celsius"<<endl;
float c,f;
cout<<endl<<endl<<"tPlease Enter you Temperature in Fahrenheit = ";
cin>>f;
c=(f-32)*5/9;
cout<<endl<<endl<<"tYour Temperature in Celsius is = "<<c;
cout<<endl<<endl<<"t============================================================== "<<endl;
cout<<endl<<endl<<"t it "<<endl;
cout<<endl<<endl<<"tPlease Enter you Temperature in Celsius = ";
cin>>c;
f=(c*9/5)+32;
cout<<endl<<endl<<"tYour Temperatures in Fahrenheit is = "<<f;
cout<<endl<<endl<<endl<<"ttO=========== 0"<<endl;
cout<<"ttl Thank you l"<<endl;
cout<<"tt0===========0"<<endl;
Chapter: 1Chapter: 1Chapter: 1Chapter: 1
Programming whit C++
---------------------------------------------------------------------------------------------------------------------------------------------------------
Submitted to: Mr.Kamran Khan
Submitted by: Padshah Gul
Course: Bs-Telecom Page No: - 4 of 52
getch();
}
Write a Program to Calculate the Total Marks, Average & Percentage of 10th Different Subjects:
#include <iostream.h>
#include <conio.h>
void main (void)
{
clrscr();
float i,c,b,p,f,t,avg,tot,per;
cout<<endl<<endl<<"tt============================================="<<endl;
cout<<"t --:( I Sarhad University of Information Technology I ):--"<<endl;
cout<<"tt============================================="<<endl;
cout<<endl<<"ttEnter the Marks of 6th Subjects"<<endl<<endl;
cout<<"tt1.tIslamic Study = ";
cin>>i;
cout<<"tt2.tCaculus & Analytical Geometry = ";
cin>>c;
cout<<"tt3.tIntroduction to Cs = ";
cin>>b;
cout<<"tt4.tBasic Communication Skill = ";
cin>>t;
cout<<"tt5.tProgramming Fundamentals = ";
cin>>f;
cout<<"tt6.tPhysics-1 = ";
cin>>p;
tot=p+f+c+t+b+i;
cout<<endl<<endl<<"t-->tTotal of 10th Subjects are = "<<tot<<endl;
avg=(p+t+b+c+f+i)/6;
cout<<endl<<"t-->tAverage of 10th Subjects are = "<<avg;
per=(tot*100)/600;
cout<<endl<<"t-->tPesentage of 10th Subjects are = "<<per;
cout<<" %";
Chapter: 1Chapter: 1Chapter: 1Chapter: 1
Programming whit C++
---------------------------------------------------------------------------------------------------------------------------------------------------------
Submitted to: Mr.Kamran Khan
Submitted by: Padshah Gul
Course: Bs-Telecom Page No: - 5 of 52
getch();
}
Creating Design of ATM Machine Display in C++:
#include <iostream.h>
#include <conio.h>
void main (void)
{
clrscr();
cout<<endl<<" ,-*^*-._.-*^*-,"<<endl; --->(34)Space
cout<<" ( ATM MACHINE )"<<endl; --->(33)Space
cout<<" ` '"<<endl; --->(34)Space
cout<<" `-.,,_,HBL,_,,.-'"<<endl; --->(34)Space
cout<<" *-._.-* "<<endl; --->(39)Space
cout<<" "<<endl; --->(42)Space
cout<<" 0-----------0 0-----------0"<<endl; ---(13-30)?
cout<<" I ONLINE I I ACCONT NO I"<<endl;
cout<<" 0-----------0 0-----------0"<<endl;
cout<<endl<<" 0-----------0 0-----------0"<<endl;
cout<<" I CASH.WITH I I PAYMENT I"<<endl;
cout<<" 0-----------0 0-----------0"<<endl;
cout<<endl<<" 0-----------0 0-----------0"<<endl;
cout<<" I BILL TRMS I I OTHERS I"<<endl;
cout<<" 0-----------0 0-----------0"<<endl;
cout<<" THANKS"<<endl; ---(42)
cout<<" ========================================================"<<endl; ---(13-56)
cout<<" Submitted by: - Padshah Gul"<<endl;
cout<<" Submitted to: - Mr.Kamran khan"<<endl;
cout<<" Submitted Date :- 20/11/2012"<<endl;
cout<<endl<<" Sarhad University, Department of Computer Science, Bs.Telecom"; -- (10)
getch();
Chapter: 1Chapter: 1Chapter: 1Chapter: 1
Programming whit C++
---------------------------------------------------------------------------------------------------------------------------------------------------------
Submitted to: Mr.Kamran Khan
Submitted by: Padshah Gul
Course: Bs-Telecom Page No: - 6 of 52
}
Time Converter:
#include <iostream.h>
#include <conio.h>
void main (void)
{
clrscr();
float age,month,day,hour,min;
long int sec;
cout<<"Enter your age in Years = ";
cin>>age;
month=age*12;
cout<<endl<<"Your age in Months = "<<month;
day=age*365;
cout<<endl<<"Your age in Days = "<<day;
hour=age*8766;
cout<<endl<<"Your age in Hours = "<<hour;
min=age*525960;
cout<<endl<<"Your age in Minutes = "<<min;
sec=age*31557600;
cout<<endl<<"Your age in Second = "<<sec;
getch();
}
Length Converter:
#include <iostream.h>
#include <conio.h>
void main (void)
{
Chapter: 1Chapter: 1Chapter: 1Chapter: 1
Programming whit C++
---------------------------------------------------------------------------------------------------------------------------------------------------------
Submitted to: Mr.Kamran Khan
Submitted by: Padshah Gul
Course: Bs-Telecom Page No: - 7 of 52
clrscr();
float k,m,cm;
cout<<endl<<endl<<"tttLength Converter"<<endl;
cout<<"tttt";
cout<<endl<<endl<<" 0==========0
0==========0"<<endl;
cout<<" l Peshawar l-----------There is distance B/W two city-----------l Nowshera l"<<endl;
cout<<" 0==========0 0==========0";
cout<<endl<<endl<<"ttttKilometer = ";
cin>>k;
m=k*1000;
cout<<endl<<"ttttMeter = "<<m;
cm=k*100000;
cout<<endl<<"ttttCentimeter = "<<cm;
cout<<endl<<"================================================================================";
cout<<"ttttMeter = ";
cin>>m;
k=m/1000;
cout<<endl<<"ttttKilometer = "<<k;
cm=m*100;
cout<<endl<<"ttttCentimeter = "<<cm;
cout<<endl<<"================================================================================";
cout<<"ttttCentimeter = ";
cin>>cm;
k=cm/100000;
cout<<endl<<"ttttKilometer = "<<k;
m=cm/100;
cout<<endl<<"ttttMeter = "<<m;
cout<<endl<<endl<<"tttt*Thank You*";
getch();
}
Chapter: 1Chapter: 1Chapter: 1Chapter: 1
Programming whit C++
---------------------------------------------------------------------------------------------------------------------------------------------------------
Submitted to: Mr.Kamran Khan
Submitted by: Padshah Gul
Course: Bs-Telecom Page No: - 8 of 52
Write a program to calculate Average age of a class of 10th students:
#include <iostream.h>
#include <conio.h>
void main (void)
{
clrscr();
float avg;
int a,b,c,d,e,f,g,h,i,j;
cout<<endl<<endl<<"t Enter the Age of 1st Student = ";
cin>>a;
cout<<endl<<"tEnter the Age of 2nd Student = ";
cin>>b;
cout<<endl<<"tEnter the Age of 3rd Student = ";
cin>>c;
cout<<endl<<"tEnter the Age of 4th Student = ";
cin>>d;
cout<<endl<<"tEnter the Age of 5th Student = ";
cin>>e;
cout<<endl<<"tEnter the Age of 6th Student = ";
cin>>f;
cout<<endl<<"tEnter the Age of 7th Student = ";
cin>>g;
cout<<endl<<"tEnter the Age of 8th Student = ";
cin>>h;
cout<<endl<<"tEnter the Age of 9th Student = ";
cin>>i;
cout<<endl<<"tEnter the Age of 10th Student = ";
cin>>j;
avg=(a+b+c+d+e+f+g+h+i+j)/10;
cout<<endl<<"tAverage the Age of 10 Students are = "<<avg;
getch();
}
Chapter: 1Chapter: 1Chapter: 1Chapter: 1
Programming whit C++
---------------------------------------------------------------------------------------------------------------------------------------------------------
Submitted to: Mr.Kamran Khan
Submitted by: Padshah Gul
Course: Bs-Telecom Page No: - 9 of 52
OR
#include <iostream.h>
#include <conio.h>
void main (void)
{
clrscr();
float avg;
int a,b,c,d,e,f,g,h,i,j;
a=24;
b=23;
c=25;
d=38;
e=18;
f=14;
g=31;
h=30;
i=37;
j=19;
avg=(a+b+c+d+e+f+g+h+i+j)/10;
cout<<"Average the Age of 10 Students are = "<<avg;
getch();
}
INCREMENT:
Prefix (++i):
#include <iostream.h>
#include <conio.h>
void main (void)
{
clrscr();
Chapter: 1Chapter: 1Chapter: 1Chapter: 1
Programming whit C++
---------------------------------------------------------------------------------------------------------------------------------------------------------
Submitted to: Mr.Kamran Khan
Submitted by: Padshah Gul
Course: Bs-Telecom Page No: - 10 of 52
float a, b, c, sum;
a=7;
b=6;
c=5;
sum=a+b+(++c);
cout<<"Sum of A+B+C ="<<sum;
cout<<"tC="<<c;
getch();
}
Output of Program:
Sum=19
C=6
Postfix (i++):
#include <iostream.h>
#include <conio.h>
void main (void)
{
clrscr();
float a, b, c, sum;
a=7;
b=6;
c=5;
sum=a+b+(c++);
cout<<"Sum of A+B+C ="<<sum;
cout<<"tC="<<c;
getch();
}
Output of Program:
Sum=18
Chapter: 1Chapter: 1Chapter: 1Chapter: 1
Programming whit C++
---------------------------------------------------------------------------------------------------------------------------------------------------------
Submitted to: Mr.Kamran Khan
Submitted by: Padshah Gul
Course: Bs-Telecom Page No: - 11 of 52
C=6
DECREMENT:
Prefix (--i):
#include <iostream.h>
#include <conio.h>
void main (void)
{
clrscr();
float a, b, c, sum;
a=4;
b=10;
c=7;
sum=a+b+(--c);
cout<<"Sum of A+B+C ="<<sum;
cout<<"tC="<<c;
getch();
}
Output of Program:
Sum=20
C=6
Postfix (i--):
#include <iostream.h>
#include <conio.h>
void main (void)
{
clrscr();
float a, b, c, sum;
a=4;
Chapter: 1Chapter: 1Chapter: 1Chapter: 1
Programming whit C++
---------------------------------------------------------------------------------------------------------------------------------------------------------
Submitted to: Mr.Kamran Khan
Submitted by: Padshah Gul
Course: Bs-Telecom Page No: - 12 of 52
b=10;
c=7;
sum=a+b+(c--);
cout<<"Sum of A+B+C ="<<sum;
cout<<"tC="<<c;
getch();
}
Output of Program:
Sum=21
C=
Chapter:Chapter:Chapter:Chapter: 2222
Programming whit C++
---------------------------------------------------------------------------------------------------------------------------------------------------------
Submitted to: Mr.Kamran Khan
Submitted by: Padshah Gul
Course: Bs-Telecom Page No: - 13 of 52
Condition Statements:
IF CONDITION:
#include <iostream.h>
#include <conio.h>
void main (void)
{
clrscr();
float age1,age2;
age1=12;
age2=18;
if(age1>age2)
cout<<"Student-1 is Older"<<endl;
if(age2>age1)
cout<<"Student-2 is Older";
getch();
}
IF CONDITION:
#include <iostream.h>
#include <conio.h>
void main (void)
{
clrscr();
int a,b;
a=100;
b=50;
if(a>b)//if a>b than show Islamabad the statement is true or Islamabad not showed the function is false
cout<<"Islamabad"<<endl;
cout<<"ok"<<endl;
getch();
}

More Related Content

DOCX
Lab manual programing
MOHAMMADSHAKEELAHMED1
 
PDF
Lab manual of C++
thesaqib
 
PDF
Al-Borj - Integration QA Test Plan v0.04
Christopher Pittman
 
PPTX
Lab # 1
Danish Noor
 
PDF
Acro6 js guide
Faina Fridman
 
PDF
Absolute beginnersseriesforwindowsphone8
Mahisa Dyan Diptya
 
PDF
Acro_js_guide
giacat_kien162
 
Lab manual programing
MOHAMMADSHAKEELAHMED1
 
Lab manual of C++
thesaqib
 
Al-Borj - Integration QA Test Plan v0.04
Christopher Pittman
 
Lab # 1
Danish Noor
 
Acro6 js guide
Faina Fridman
 
Absolute beginnersseriesforwindowsphone8
Mahisa Dyan Diptya
 
Acro_js_guide
giacat_kien162
 

Viewers also liked (8)

PPT
Practical basics on c++
Marco Izzotti
 
PPTX
C++:Lab 2
سلمى شطا
 
PPTX
C++ lab -4
سلمى شطا
 
PDF
Practical C++ Generative Programming
Schalk Cronjé
 
PDF
c++ lab manual
Shrunkhala Wankhede
 
DOCX
12th CBSE Practical File
Ashwin Francis
 
DOCX
C++ project on police station software
dharmenderlodhi021
 
DOCX
Computer science project work
rahulchamp2345
 
Practical basics on c++
Marco Izzotti
 
C++:Lab 2
سلمى شطا
 
C++ lab -4
سلمى شطا
 
Practical C++ Generative Programming
Schalk Cronjé
 
c++ lab manual
Shrunkhala Wankhede
 
12th CBSE Practical File
Ashwin Francis
 
C++ project on police station software
dharmenderlodhi021
 
Computer science project work
rahulchamp2345
 
Ad

Similar to C++ practical lab (20)

DOCX
Important C program of Balagurusamy Book
Abir Hossain
 
DOCX
CST2403 NOTES
Clara Irizarry
 
DOC
Course Breakup Plan- C
swatisinghal
 
PDF
Object Oriented Programming Using C++ Practical File
Harjinder Singh
 
DOC
project report in C++ programming and SQL
vikram mahendra
 
DOCX
CS291(C Programming) assignment
Kuntal Bhowmick
 
DOCX
Computer Practical XII
Ûťţåm Ğűpţä
 
PDF
Common problems solving using c
ArghodeepPaul
 
DOCX
Practical File of c++.docx lab manual program question
vidhimangal05
 
DOCX
Best c programs
AbhishekSharma471920
 
PDF
Simple c-programs
rashmi322
 
DOCX
Loops in C++
Abbas Ajmal
 
PDF
Sample Paper 2 Class XI (Computer Science)
Poonam Chopra
 
PDF
How to program in c++ with 100 examples
Shahid Riaz
 
PDF
Introduction to Basic C++ Program Examples .pdf
simegnew Ataley
 
DOCX
HSc Computer Science Practical Slip for Class 12
Aditi Bhushan
 
PPT
Apclass (2)
geishaannealagos
 
PDF
Mmt 001
sujatam8
 
DOCX
Oop lab assignment 01
Drjilesh
 
Important C program of Balagurusamy Book
Abir Hossain
 
CST2403 NOTES
Clara Irizarry
 
Course Breakup Plan- C
swatisinghal
 
Object Oriented Programming Using C++ Practical File
Harjinder Singh
 
project report in C++ programming and SQL
vikram mahendra
 
CS291(C Programming) assignment
Kuntal Bhowmick
 
Computer Practical XII
Ûťţåm Ğűpţä
 
Common problems solving using c
ArghodeepPaul
 
Practical File of c++.docx lab manual program question
vidhimangal05
 
Best c programs
AbhishekSharma471920
 
Simple c-programs
rashmi322
 
Loops in C++
Abbas Ajmal
 
Sample Paper 2 Class XI (Computer Science)
Poonam Chopra
 
How to program in c++ with 100 examples
Shahid Riaz
 
Introduction to Basic C++ Program Examples .pdf
simegnew Ataley
 
HSc Computer Science Practical Slip for Class 12
Aditi Bhushan
 
Apclass (2)
geishaannealagos
 
Mmt 001
sujatam8
 
Oop lab assignment 01
Drjilesh
 
Ad

Recently uploaded (20)

PPTX
database slide on modern techniques for optimizing database queries.pptx
aky52024
 
PDF
settlement FOR FOUNDATION ENGINEERS.pdf
Endalkazene
 
PDF
Introduction to Data Science: data science process
ShivarkarSandip
 
PDF
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
PDF
July 2025: Top 10 Read Articles Advanced Information Technology
ijait
 
DOCX
SAR - EEEfdfdsdasdsdasdasdasdasdasdasdasda.docx
Kanimozhi676285
 
PDF
top-5-use-cases-for-splunk-security-analytics.pdf
yaghutialireza
 
PPTX
22PCOAM21 Session 2 Understanding Data Source.pptx
Guru Nanak Technical Institutions
 
PPTX
Information Retrieval and Extraction - Module 7
premSankar19
 
PPTX
AgentX UiPath Community Webinar series - Delhi
RohitRadhakrishnan8
 
PDF
dse_final_merit_2025_26 gtgfffffcjjjuuyy
rushabhjain127
 
PPTX
MT Chapter 1.pptx- Magnetic particle testing
ABCAnyBodyCanRelax
 
PPTX
MSME 4.0 Template idea hackathon pdf to understand
alaudeenaarish
 
PPT
Ppt for engineering students application on field effect
lakshmi.ec
 
PDF
Advanced LangChain & RAG: Building a Financial AI Assistant with Real-Time Data
Soufiane Sejjari
 
PPTX
22PCOAM21 Data Quality Session 3 Data Quality.pptx
Guru Nanak Technical Institutions
 
PDF
Packaging Tips for Stainless Steel Tubes and Pipes
heavymetalsandtubes
 
PDF
Chad Ayach - A Versatile Aerospace Professional
Chad Ayach
 
PPTX
Victory Precisions_Supplier Profile.pptx
victoryprecisions199
 
PPTX
Introduction of deep learning in cse.pptx
fizarcse
 
database slide on modern techniques for optimizing database queries.pptx
aky52024
 
settlement FOR FOUNDATION ENGINEERS.pdf
Endalkazene
 
Introduction to Data Science: data science process
ShivarkarSandip
 
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
July 2025: Top 10 Read Articles Advanced Information Technology
ijait
 
SAR - EEEfdfdsdasdsdasdasdasdasdasdasdasda.docx
Kanimozhi676285
 
top-5-use-cases-for-splunk-security-analytics.pdf
yaghutialireza
 
22PCOAM21 Session 2 Understanding Data Source.pptx
Guru Nanak Technical Institutions
 
Information Retrieval and Extraction - Module 7
premSankar19
 
AgentX UiPath Community Webinar series - Delhi
RohitRadhakrishnan8
 
dse_final_merit_2025_26 gtgfffffcjjjuuyy
rushabhjain127
 
MT Chapter 1.pptx- Magnetic particle testing
ABCAnyBodyCanRelax
 
MSME 4.0 Template idea hackathon pdf to understand
alaudeenaarish
 
Ppt for engineering students application on field effect
lakshmi.ec
 
Advanced LangChain & RAG: Building a Financial AI Assistant with Real-Time Data
Soufiane Sejjari
 
22PCOAM21 Data Quality Session 3 Data Quality.pptx
Guru Nanak Technical Institutions
 
Packaging Tips for Stainless Steel Tubes and Pipes
heavymetalsandtubes
 
Chad Ayach - A Versatile Aerospace Professional
Chad Ayach
 
Victory Precisions_Supplier Profile.pptx
victoryprecisions199
 
Introduction of deep learning in cse.pptx
fizarcse
 

C++ practical lab

  • 2. Programming whit C++ TABLE OF CONTENTSTABLE OF CONTENTSTABLE OF CONTENTSTABLE OF CONTENTS Page No Submitted to: Mr.Kamran Khan Submitted by: Padshah Gul Course: Bs-Telecom 1. WRITE A PROGRAM TO SHOW YOUR DESIRE TEXT ON SCREEN:…………………………………………………………………… 1 2. FINDING VELOCITY OF DRAM ( ∏∏∏∏R2 .H): ……………………………………………………………………………………………………….. 1 3. USING SOME ARITHMETIC OPERATIONS:……………………………………………………………………………………………………… 2 4. TEMPERATURE CALCULATION:……………………………………………………………………………………………………………………… 3 CONVERT CELSIUS TO FAHRENHEIT: .......................................................................................................................................3 CONVERT FAHRENHEIT TO CELSIUS: .......................................................................................................................................3 WRITE A PROGRAM TO CALCULATE THE TOTAL MARKS, AVERAGE & PERCENTAGE OF 10TH DIFFERENT SUBJECTS:...............................4 CREATING DESIGN OF ATM MACHINE DISPLAY IN C++:............................................................................................................5 TIME CONVERTER:..............................................................................................................................................................6 LENGTH CONVERTER:..........................................................................................................................................................6 WRITE A PROGRAM TO CALCULATE AVERAGE AGE OF A CLASS OF 10TH STUDENTS: .........................................................................8 5. INCREMENT:………………………………………………………………………………………………………………………………………………... 9 PREFIX (++I): ....................................................................................................................................................................9 POSTFIX (I++): ................................................................................................................................................................10 6. DECREMENT:………………………………………………………………………………………………………………………………………………… 11 PREFIX (--I):....................................................................................................................................................................11 POSTFIX (I--):..................................................................................................................................................................11 7. CONDITION STATEMENTS:……………………………………………………………………………………………………………………………. 13 IF CONDITION:.............................................................................................................................................................13 IF CONDITION:.............................................................................................................................................................13 IF CONDITION:.............................................................................................................................................................14 IF-ELSE: .........................................................................................................................................................................14 IF-ELSE: .........................................................................................................................................................................15 WRITE A PROGRAM TO CHECK WITHER THE GIVEN NUMBER IS ODD OR EVEN. ............................................................................16 USING (IF-ELSE) ...............................................................................................................................................................16 WRITE A PROGRAM TO CHECK A PERSON IS MALE OR FEMALE BY INPUT CHARACTER.......................................................................16 USING (IF-ELSE):..............................................................................................................................................................16 WRITE A PROGRAM TO CHECK POSITIVE NUMBER AND NEGATIVE NUMBER...................................................................................17 USING (IF-ELSE):..............................................................................................................................................................17 NESTED IF ELSE:...............................................................................................................................................................18 USING OF SIMPLE ARITHMETIC OPERATORS (USING IF ELSE): .....................................................................................................19 A PROGRAM IN WHICH MAKERS OBTAINED IN ANY SUBJECT INPUT THROUGH KEYBOARD .................................................................20 CALCULATE TOTAL, PERCENTAGE AND AVERAGE USE LOGICAL OPERATORS: .................................................................................20 8. SWITCH STATEMENT:…………………………………………………………………………………………………………………………………… 21 -- :( SPORTS REGISTRATION MENU ): --........................................................................................................................21 9. LOOPS:………………………………………………………………………………………………………………………………………………………… 26 WRITE A PROGRAM TO PRINT FIVE TIMES “I LOVE PAKISTAN" (USING WHILE LOOP):....................................................................26 WRITE A PROGRAM TO PRINT NATURAL NUMBER FROM 1 TO 100 IN ASCENDING FORM BY (USING WHILE LOOP):..........................26 WRITE A PROGRAM TO PRINT NATURAL NUMBER FROM 10 TO 1 IN DESCENDING FORM BY (USING WHILE LOOP): ...........................27
  • 3. Programming whit C++ TABLE OF CONTENTSTABLE OF CONTENTSTABLE OF CONTENTSTABLE OF CONTENTS Page No Submitted to: Mr.Kamran Khan Submitted by: Padshah Gul Course: Bs-Telecom WRITE A PROGRAM TO PRINT FIRST EVEN NUMBER FROM 1 TO 100 BY (USING WHILE LOOP):.....................................................28 WRITE A PROGRAM TO PRINT FIRST ODD NUMBER FROM 1 TO 100 BY (USING WHILE LOOP):.......................................................28 WRITE A PROGRAM TO FIND THE SUM OF FOLLOWING SERIES BY (USING WHILE LOOP).................................................................29 USING DO-WHILE LOOP: ....................................................................................................................................................29 WRITE A PROGRAM TO PRINT NATURAL NUMBER FROM 1 TO 10 AND SUM IT BY...........................................................................30 (USING DO-WHILE LOOP):..................................................................................................................................................30 WRITE A PROGRAM TO PRINT TABLE OF TWO BY (USING FOR LOOP): ..........................................................................................31 WRITE A PROGRAM TO PRINT TABLE OF ANY NUMBER BY (USING FOR LOOP):...............................................................................32 NATURAL NUMBER FROM (1 TO 10 AND FORM 10 TO 1) BY (USING FOR LOOP):....................................................................32 NESTED LOOPS:...............................................................................................................................................................33 10. ARRAY:………………………………………………………………………………………………………………………………………………………… 34 WRITE A PROGRAM IN ARRAY TO PRINT FIXED NUMBER FROM INPUT:.........................................................................................34 WRITE A PROGRAM IN ARRAY TO PRINT VARIABLE NUMBER (USER CHOICE) CALCULATE SUM AND AVERAGE:.....................................34 WRITE A PROGRAM IN ARRAY TO ENTER VALUE AND THEN PRINT VALUE IN REVERSE ORDER...........................................................35 WRITE A PROGRAM TO FIND OUT AND PRINT THE MAXIMUM VALUE IN THE ARRAY: ......................................................................36 WRITE A PROGRAM TO FIND OUT AND PRINT THE MINIMUM VALUE IN THE ARRAY:.......................................................................37 WRITE A PROGRAM IN A CHARACTER TYPE ARRAY TO COPY "FIRST" ARRAY INTO "SECOND" ARRAYS:................................................37 WRITE A PROGRAM TO INPUT DATA INTO TWO DIFFERENT ARRAYS AND THEN SUM INTO A THIRD ARRAY............................................38 STRING VARIABLE (NULL CHARACTER)..................................................................................................................................39 WRITE A PROGRAM IN A STRING TYPE ARRAY TO COPY "FIRST" ARRAY INTO "SECOND" ARRAYS:......................................................39 TWO DIMENSION ARRAY:..................................................................................................................................................40 WRITE A PROGRAM TO PRINT THE OUTPUT OF FOLLOWING TABLE. .............................................................................................40 WRITE A PROGRAM TO PRINT TABLE OF 4X5(4 ROWS & 5 COLUMNS). .......................................................................................41 11. STRUCTURES:……………………………………………………………………………………………………………………………………………….. 42 WRITE A PROGRAM TO INPUT DATA INTO AND THEN PRINT DATA FROM THE MEMBERS OF STRUCTURE: .............................................42 WRITE A PROGRAM TO DEFINE A STRUCTURE WITH FIVE MEMBERS. THE FIRST MEMBER BE STUDENT NAME AND THE OTHER BE OBTAINED MARKS IN FOUR SUBJECTS. .................................................................................................................................................43 WRITE A PROGRAM TO INPUT DATA IN STRUCTURE AND THEN TO FIND OUT THE SUM OF MARKS. STORE THE RESULT IN THE MEMBER “TOTAL” PRINT THE DATA ON THE SCREEN. ............................................................................................................................44 12. FUNCTION:………………………………………………………………….……………………………………………………………..……………….. 46 WRITE A PROGRAM TO PRINT A MESSAGE ON THE SCREEN USING A FUNCTION.............................................................................46 WRITE A PROGRAM TO PASS THREE VARIABLES AS PARAMETERS FROM INPUT TO THE FUNCTION TO CALCULATE THEIR SUM...................46 WRITE A PROGRAM TO PASS THREE VARIABLES AS PARAMETERS FROM USER TO THE FUNCTION TO CALCULATE THEIR SUM....................47 WRITE A PROGRAM TO PRINT A TABLE OF A GIVEN NUMBER USING FUNCTION..............................................................................48 WRITE A PROGRAM FOR CALCULATOR BY PASSING THREE ARGUMENTS TO THE FUNCTION. .............................................................49 1ST AND 3RD ARE NUMERIC NUMBERS AND 2ND IS ARITHMETIC OPERATORS...............................................................................49 WRITE A PROGRAM TO FIND THE MAXIMUM NUMBER FROM AN ARRAY BY USING THE FUNCTION.....................................................50 LOCAL VARIABLES IN FUNCTION: .........................................................................................................................................51 GLOBAL VARIABLES IN FUNCTION:.......................................................................................................................................52
  • 4. Chapter: 1Chapter: 1Chapter: 1Chapter: 1 Programming whit C++ --------------------------------------------------------------------------------------------------------------------------------------------------------- Submitted to: Mr.Kamran Khan Submitted by: Padshah Gul Course: Bs-Telecom Page No: - 1 of 52 Write a program to show your Desire text on screen: #include <iostream.h> #include <conio.h> void main (void) { clrscr(); cout<<"My name is Padshah Gul."<<endl; cout<<"I am student of Sarhad University."<<endl; cout<<"I am from Afghanistan."<<endl; getch(); } Output of Program: My name is Padshah Gul. I am student of Sarhad University. I am from Afghanistan. Finding velocity of dram ( ∏∏∏∏r2.h): #include <iostream.h> #include <conio.h> void main (void) { clrscr(); float h=8; float r=5; float pi=3.14; float v=h*r*r*pi; cout<<"Result is "<<v; getch(); Height= 8 cm 2r=10 cm
  • 5. Chapter: 1Chapter: 1Chapter: 1Chapter: 1 Programming whit C++ --------------------------------------------------------------------------------------------------------------------------------------------------------- Submitted to: Mr.Kamran Khan Submitted by: Padshah Gul Course: Bs-Telecom Page No: - 2 of 52 } Using some arithmetic operations: Like ( +, -, *, /, %) #include <iostream.h> #include <conio.h> void main (void) { clrscr(); int p,s,m,d,r; p=7+5; s=10-3; m=4*2; d=10/2; r=11%5; cout<<"output of arithmetic operators"<<endl; cout<<endl<<"Addition of 8 and 2 is = "<<p<<endl; cout<<"Subtraction of 10 and 3 is = "<<s<<endl; cout<<"Multiplication of 4 and 2 is = "<<m<<endl; cout<<"Division of 10 and 2 is = "<<d<<endl; cout<<"Remainder of 5/2 is = "<<r<<endl; getch(); } Output of the program: Addition of 8 and 2 is = 10 Subtraction of 10 and 3 is = 7 Multiplication of 4 and 2 is = 8 Division of 10 and 2 is = 5
  • 6. Chapter: 1Chapter: 1Chapter: 1Chapter: 1 Programming whit C++ --------------------------------------------------------------------------------------------------------------------------------------------------------- Submitted to: Mr.Kamran Khan Submitted by: Padshah Gul Course: Bs-Telecom Page No: - 3 of 52 Remainder of 5/2 is = 1 Temperature Calculation: Convert Celsius to Fahrenheit: Convert Fahrenheit to Celsius: #include <iostream.h> #include <conio.h> void main(void) { clrscr(); cout<<endl<<endl<<"ttt Temperature Calculation"<<endl; cout<<"ttt"<<endl; cout<<endl<<endl<<"t0-------------0"<<endl; cout<<"tl Well Come!! l"<<endl; cout<<"t0-------------0"<<endl; cout<<endl<<endl<<"tconvert Fahrenheit to Celsius"<<endl; float c,f; cout<<endl<<endl<<"tPlease Enter you Temperature in Fahrenheit = "; cin>>f; c=(f-32)*5/9; cout<<endl<<endl<<"tYour Temperature in Celsius is = "<<c; cout<<endl<<endl<<"t============================================================== "<<endl; cout<<endl<<endl<<"t it "<<endl; cout<<endl<<endl<<"tPlease Enter you Temperature in Celsius = "; cin>>c; f=(c*9/5)+32; cout<<endl<<endl<<"tYour Temperatures in Fahrenheit is = "<<f; cout<<endl<<endl<<endl<<"ttO=========== 0"<<endl; cout<<"ttl Thank you l"<<endl; cout<<"tt0===========0"<<endl;
  • 7. Chapter: 1Chapter: 1Chapter: 1Chapter: 1 Programming whit C++ --------------------------------------------------------------------------------------------------------------------------------------------------------- Submitted to: Mr.Kamran Khan Submitted by: Padshah Gul Course: Bs-Telecom Page No: - 4 of 52 getch(); } Write a Program to Calculate the Total Marks, Average & Percentage of 10th Different Subjects: #include <iostream.h> #include <conio.h> void main (void) { clrscr(); float i,c,b,p,f,t,avg,tot,per; cout<<endl<<endl<<"tt============================================="<<endl; cout<<"t --:( I Sarhad University of Information Technology I ):--"<<endl; cout<<"tt============================================="<<endl; cout<<endl<<"ttEnter the Marks of 6th Subjects"<<endl<<endl; cout<<"tt1.tIslamic Study = "; cin>>i; cout<<"tt2.tCaculus & Analytical Geometry = "; cin>>c; cout<<"tt3.tIntroduction to Cs = "; cin>>b; cout<<"tt4.tBasic Communication Skill = "; cin>>t; cout<<"tt5.tProgramming Fundamentals = "; cin>>f; cout<<"tt6.tPhysics-1 = "; cin>>p; tot=p+f+c+t+b+i; cout<<endl<<endl<<"t-->tTotal of 10th Subjects are = "<<tot<<endl; avg=(p+t+b+c+f+i)/6; cout<<endl<<"t-->tAverage of 10th Subjects are = "<<avg; per=(tot*100)/600; cout<<endl<<"t-->tPesentage of 10th Subjects are = "<<per; cout<<" %";
  • 8. Chapter: 1Chapter: 1Chapter: 1Chapter: 1 Programming whit C++ --------------------------------------------------------------------------------------------------------------------------------------------------------- Submitted to: Mr.Kamran Khan Submitted by: Padshah Gul Course: Bs-Telecom Page No: - 5 of 52 getch(); } Creating Design of ATM Machine Display in C++: #include <iostream.h> #include <conio.h> void main (void) { clrscr(); cout<<endl<<" ,-*^*-._.-*^*-,"<<endl; --->(34)Space cout<<" ( ATM MACHINE )"<<endl; --->(33)Space cout<<" ` '"<<endl; --->(34)Space cout<<" `-.,,_,HBL,_,,.-'"<<endl; --->(34)Space cout<<" *-._.-* "<<endl; --->(39)Space cout<<" "<<endl; --->(42)Space cout<<" 0-----------0 0-----------0"<<endl; ---(13-30)? cout<<" I ONLINE I I ACCONT NO I"<<endl; cout<<" 0-----------0 0-----------0"<<endl; cout<<endl<<" 0-----------0 0-----------0"<<endl; cout<<" I CASH.WITH I I PAYMENT I"<<endl; cout<<" 0-----------0 0-----------0"<<endl; cout<<endl<<" 0-----------0 0-----------0"<<endl; cout<<" I BILL TRMS I I OTHERS I"<<endl; cout<<" 0-----------0 0-----------0"<<endl; cout<<" THANKS"<<endl; ---(42) cout<<" ========================================================"<<endl; ---(13-56) cout<<" Submitted by: - Padshah Gul"<<endl; cout<<" Submitted to: - Mr.Kamran khan"<<endl; cout<<" Submitted Date :- 20/11/2012"<<endl; cout<<endl<<" Sarhad University, Department of Computer Science, Bs.Telecom"; -- (10) getch();
  • 9. Chapter: 1Chapter: 1Chapter: 1Chapter: 1 Programming whit C++ --------------------------------------------------------------------------------------------------------------------------------------------------------- Submitted to: Mr.Kamran Khan Submitted by: Padshah Gul Course: Bs-Telecom Page No: - 6 of 52 } Time Converter: #include <iostream.h> #include <conio.h> void main (void) { clrscr(); float age,month,day,hour,min; long int sec; cout<<"Enter your age in Years = "; cin>>age; month=age*12; cout<<endl<<"Your age in Months = "<<month; day=age*365; cout<<endl<<"Your age in Days = "<<day; hour=age*8766; cout<<endl<<"Your age in Hours = "<<hour; min=age*525960; cout<<endl<<"Your age in Minutes = "<<min; sec=age*31557600; cout<<endl<<"Your age in Second = "<<sec; getch(); } Length Converter: #include <iostream.h> #include <conio.h> void main (void) {
  • 10. Chapter: 1Chapter: 1Chapter: 1Chapter: 1 Programming whit C++ --------------------------------------------------------------------------------------------------------------------------------------------------------- Submitted to: Mr.Kamran Khan Submitted by: Padshah Gul Course: Bs-Telecom Page No: - 7 of 52 clrscr(); float k,m,cm; cout<<endl<<endl<<"tttLength Converter"<<endl; cout<<"tttt"; cout<<endl<<endl<<" 0==========0 0==========0"<<endl; cout<<" l Peshawar l-----------There is distance B/W two city-----------l Nowshera l"<<endl; cout<<" 0==========0 0==========0"; cout<<endl<<endl<<"ttttKilometer = "; cin>>k; m=k*1000; cout<<endl<<"ttttMeter = "<<m; cm=k*100000; cout<<endl<<"ttttCentimeter = "<<cm; cout<<endl<<"================================================================================"; cout<<"ttttMeter = "; cin>>m; k=m/1000; cout<<endl<<"ttttKilometer = "<<k; cm=m*100; cout<<endl<<"ttttCentimeter = "<<cm; cout<<endl<<"================================================================================"; cout<<"ttttCentimeter = "; cin>>cm; k=cm/100000; cout<<endl<<"ttttKilometer = "<<k; m=cm/100; cout<<endl<<"ttttMeter = "<<m; cout<<endl<<endl<<"tttt*Thank You*"; getch(); }
  • 11. Chapter: 1Chapter: 1Chapter: 1Chapter: 1 Programming whit C++ --------------------------------------------------------------------------------------------------------------------------------------------------------- Submitted to: Mr.Kamran Khan Submitted by: Padshah Gul Course: Bs-Telecom Page No: - 8 of 52 Write a program to calculate Average age of a class of 10th students: #include <iostream.h> #include <conio.h> void main (void) { clrscr(); float avg; int a,b,c,d,e,f,g,h,i,j; cout<<endl<<endl<<"t Enter the Age of 1st Student = "; cin>>a; cout<<endl<<"tEnter the Age of 2nd Student = "; cin>>b; cout<<endl<<"tEnter the Age of 3rd Student = "; cin>>c; cout<<endl<<"tEnter the Age of 4th Student = "; cin>>d; cout<<endl<<"tEnter the Age of 5th Student = "; cin>>e; cout<<endl<<"tEnter the Age of 6th Student = "; cin>>f; cout<<endl<<"tEnter the Age of 7th Student = "; cin>>g; cout<<endl<<"tEnter the Age of 8th Student = "; cin>>h; cout<<endl<<"tEnter the Age of 9th Student = "; cin>>i; cout<<endl<<"tEnter the Age of 10th Student = "; cin>>j; avg=(a+b+c+d+e+f+g+h+i+j)/10; cout<<endl<<"tAverage the Age of 10 Students are = "<<avg; getch(); }
  • 12. Chapter: 1Chapter: 1Chapter: 1Chapter: 1 Programming whit C++ --------------------------------------------------------------------------------------------------------------------------------------------------------- Submitted to: Mr.Kamran Khan Submitted by: Padshah Gul Course: Bs-Telecom Page No: - 9 of 52 OR #include <iostream.h> #include <conio.h> void main (void) { clrscr(); float avg; int a,b,c,d,e,f,g,h,i,j; a=24; b=23; c=25; d=38; e=18; f=14; g=31; h=30; i=37; j=19; avg=(a+b+c+d+e+f+g+h+i+j)/10; cout<<"Average the Age of 10 Students are = "<<avg; getch(); } INCREMENT: Prefix (++i): #include <iostream.h> #include <conio.h> void main (void) { clrscr();
  • 13. Chapter: 1Chapter: 1Chapter: 1Chapter: 1 Programming whit C++ --------------------------------------------------------------------------------------------------------------------------------------------------------- Submitted to: Mr.Kamran Khan Submitted by: Padshah Gul Course: Bs-Telecom Page No: - 10 of 52 float a, b, c, sum; a=7; b=6; c=5; sum=a+b+(++c); cout<<"Sum of A+B+C ="<<sum; cout<<"tC="<<c; getch(); } Output of Program: Sum=19 C=6 Postfix (i++): #include <iostream.h> #include <conio.h> void main (void) { clrscr(); float a, b, c, sum; a=7; b=6; c=5; sum=a+b+(c++); cout<<"Sum of A+B+C ="<<sum; cout<<"tC="<<c; getch(); } Output of Program: Sum=18
  • 14. Chapter: 1Chapter: 1Chapter: 1Chapter: 1 Programming whit C++ --------------------------------------------------------------------------------------------------------------------------------------------------------- Submitted to: Mr.Kamran Khan Submitted by: Padshah Gul Course: Bs-Telecom Page No: - 11 of 52 C=6 DECREMENT: Prefix (--i): #include <iostream.h> #include <conio.h> void main (void) { clrscr(); float a, b, c, sum; a=4; b=10; c=7; sum=a+b+(--c); cout<<"Sum of A+B+C ="<<sum; cout<<"tC="<<c; getch(); } Output of Program: Sum=20 C=6 Postfix (i--): #include <iostream.h> #include <conio.h> void main (void) { clrscr(); float a, b, c, sum; a=4;
  • 15. Chapter: 1Chapter: 1Chapter: 1Chapter: 1 Programming whit C++ --------------------------------------------------------------------------------------------------------------------------------------------------------- Submitted to: Mr.Kamran Khan Submitted by: Padshah Gul Course: Bs-Telecom Page No: - 12 of 52 b=10; c=7; sum=a+b+(c--); cout<<"Sum of A+B+C ="<<sum; cout<<"tC="<<c; getch(); } Output of Program: Sum=21 C=
  • 16. Chapter:Chapter:Chapter:Chapter: 2222 Programming whit C++ --------------------------------------------------------------------------------------------------------------------------------------------------------- Submitted to: Mr.Kamran Khan Submitted by: Padshah Gul Course: Bs-Telecom Page No: - 13 of 52 Condition Statements: IF CONDITION: #include <iostream.h> #include <conio.h> void main (void) { clrscr(); float age1,age2; age1=12; age2=18; if(age1>age2) cout<<"Student-1 is Older"<<endl; if(age2>age1) cout<<"Student-2 is Older"; getch(); } IF CONDITION: #include <iostream.h> #include <conio.h> void main (void) { clrscr(); int a,b; a=100; b=50; if(a>b)//if a>b than show Islamabad the statement is true or Islamabad not showed the function is false cout<<"Islamabad"<<endl; cout<<"ok"<<endl; getch(); }