appendix lab manual for programming skills
Post on 14-Jan-2016
42 Views
Preview:
DESCRIPTION
TRANSCRIPT
AppendixLab Manual for
Programming Skills
1
Symbols used in Writing Programs { opening curly bracket
} closing curly bracket
# hash sign or number sign (shift+3)
( ) small brackets
“aaaa ” double quotes
‘ aaaa ‘ single quotes
, comma
; semicolon
void main( ) main function
// is used for making comment in one line
/* is used for making comment in block form */ 2
Unit: 1Objective: To understand the concept of comments, input ,output
Statements and data types .
//PROGRAM-1 to demonstrate cout ... COMMENTS
// is used for making comment in program
#include<iostream> //PREPROCESSOR
void main( ) // FUNCTION WITH RETURN TYPE VOID
{ //Beginning
cout<<"WELCOME TO VC++ World "<<endl; // cout IS AN OBJECT IN C++, endl IS END OF LINE,
cout<<“Warning! Get ready”<<endl;
//; IS CALLED TERMINATOR.
} // End
3
Unit: 1Program Explanation
#include <iostream> Include directive tells the compiler
Where to find information about input and output that are used in
Your program cout (see-out) used for output to the monitor “<<“ is the insertion operator ‘\n’ causes a new line to be started on the monitor
4
Unit: 1//PROGRAM-2 to demonstrate cin cout (int, float,char)...#include<iostream>
void main( )
{
int a;
float b;
char c;
cout<<"ENTER AN INTEGER VALUE"<<endl;
cin>>a;
cout<<"ENTER A FLOAT VALUE"<<endl;
cin>>b;
cout<<"ENTER A CHARACTER OR Alphabet"<<endl;
cin>>c;
cout<<"INTEGER= "<<a<<"\tFLOAT= "<<b<<"\tCHARECTER= "<<c<<endl;
}
5
Unit: 1 Program Explanation
cin >> a;
cin (see-in) used for input from the keyboard
“>>” extracts data from the keyboard
Think of cin as a name for the keyboard “>>” points from the keyboard to a variable where the data is stored
6
Unit: 1//PROGRAM-3 to find Sum and Average of two numbers.
#include<iostream>
void main( )
{
folat a,b;
float sum,avg;
cout<<"ENTER TWO NUMBERS"<<endl;
cin>>a>>b;
sum = a + b;
avg = sum/2;
cout<<"SUM = "<<sum<<"\n AVARAGE = "<<avg<<endl;
}
7
Unit: 1//PROGRAM-4 to find Sum and Average of three numbers.
#include<iostream>
void main( )
{
folat a,b,c;
float sum,avg;
cout<<"ENTER THREE NUMBERS"<<endl;
cin>>a>>b>>c;
sum = a + b + c;
avg = sum/3;
cout<<"SUM = "<<sum<<"\n AVARAGE = "<<avg<<endl;
}
8
Uint: 1Check Your Programming skills:
Write a C++ program to find the difference between two
Numbers? Write a C++ program to find the product of three numbers? Convert feet to inches given 1 feet= 12 inches?
9
Unit: 2Objectives: To implement the concept of operators
// PROGRAM-5 to find area of a circle.
#include<iostream>
void main( )
{
float r,area;
const float pi=3.147;
cout<<"ENTER RADIUS OF CIRCLE"<<endl;
cin>>r;
area = pi*r*r;
cout<<"AREA OF CIRCLE = "<<area<<endl;
}
10
Unit: 2//Program -6 to display Pay slip of an employee
#include<iostream>
void main ()
{
double GSal,NSal,ded,basic,da;
const double Housing=1000.00, TA=500.00;
cout<<"Enter Basic Salary\n";
cin>>basic;
cout<<"Enter Deduction Amount\n";
cin>>ded;
da=basic*0.2;
GSal=basic+da+Housing+TA;
NSal=GSal-ded;11
Unit: 2…..
cout<<"\t\t\t\tBasic :\t"<<basic<<endl;
cout<<"\t\t\t\tDA :\t"<<da<<endl;
cout<<"\t\t\t\tHousing :\t"<<Housing<<endl;
cout<<"\t\t\t\tTravelling :\t"<<TA<<endl;
cout<<"\t\t\t\tGross salary :\t"<<GSal<<endl;
cout<<"\t\t\t\tDeduction :\t"<<ded<<endl;
cout<<"\t\t\t\tNet Salary :\t"<<NSal<<endl<<endl<<endl;
}
12
Unit: 2Check Your Programming skills
Write a C++ program to find the area of Square? Write a C++ program to find the volume of Square? Convert centigrade to Fahrenheit given F=((C/5)*9) + 32? Write a C++ program to create an invoice of item?
13
Unit: 3Objectives:To understand the concepts of conditional statements
Or control structure.( if – else )
//Program -7 to find Number is MAX or MIN#include<iostream>
void main()
{
int a,b;
cout<<"Enter two numbers\n";
cin>>a>>b;
if(a>b)
cout<<a<<" is MAXIMUM "<<b<<" is MINIMUM\n";
else
cout<<b<<" is MAXIMUM "<<a<<" is MINIMUM\n";
}14
Unit: 3//Program -8 to find number is ODD OR EVEN
#include<iostream>
void main()
{
int num;
cout<<"Enter a number\n";
cin>>num;
if(num%2==0)
cout<<num<<" is an Even Number\n";
else
cout<<num<<" is an Odd Number\n";
}
15
Unit: 3//Program -9 to find the Grade of students
#include<iostream>
void main()
{
int mark;
char grade;
cout<<"Enter mark";
cin >> mark;
if(mark >= 90 && mark <= 100 )
grade='A';
if(mark >= 80 && mark <= 89 )
grade='B';
16
Unit: 3……
if(mark >= 70 && mark <= 79 )
grade='C';
if(mark >= 60 && mark <= 69 )
grade='D';
if(mark < 60 )
grade='F';
cout<<"Mark"<<"\t"<<"Grade"<<endl;
cout<<mark<<"\t"<<grade<<endl;
}
17
Unit: 3Check Your Programming Skills:
Write a C++ program to find the largest among three numbers by
using if-else? Write a C++ program to find whether the given number is Prime
number or not by using if-else? Write a C++ program to find whether the given number is
divisible of 5 or not by using if-else?
18
Unit: 4Objectives:To understand the concepts of conditional statements
Or control structure.( Switch – Case )//Program-10 to check the day of week by using SWITCH-CASE
#include<iostream>
void main()
{
int x;
cout<<"Enter number"<<endl;
cin>>x;
switch(x)
{
case 1:
cout<<"Saturday"<<endl;
break;19
Unit: 4……
case 2:
cout<<"Sunday"<<endl;
break;
case 3:
cout<<"Monday"<<endl;
break;
case 4:
cout<<"Tuesday"<<endl;
break;
case 5:
cout<<"Wednesday"<<endl;
break;20
Unit: 4……
case 6:
cout<<"Thursday"<<endl;
break;
case 7:
cout<<"Friday"<<endl;
break;
default:
cout<<"Error"<<endl;
}
}
21
Unit: 4// Program- 11 Menu driven program ( + , * , - , %) using
switch case statement
#include<iostream>
void main()
{
int n1, n2;
char op;
cout<<"Enter first number"; cin >> n1;
cout<<"Enter second number"; cin >> n2;
cout<<"Enter operator(*, /, + -)"; cin >> op;
switch (op)
{
case '*‘:cout<<n1<<op<<n2<<"="<<(n1*n2)<<endl;break;
22
Unit: 4…..
case '/‘:cout<<n1<<op<<n2<<"="<<(n1/n2)<<endl;break;
case '+‘:cout<<n1<<op<<n2<<"="<<(n1+n2)<<endl;break;
case '-‘:cout<<n1<<op<<n2<<"="<<(n1-n2)<<endl;break;
default:cout<<"Invalid oprator"<<endl;break;
} }
23
Unit: 4Check Your Programming Skills:
Write a C++ program to find month of years by using a
switch case statement? Write a menu driven program to calculate different currency
Conversions?
24
Unit: 5Objectives:To understand the concepts of conditional statements
Or control structure.( Loops: FOR, WHILE, DO WHILE )// Program-12 to print natural numbers from 1 to 30 using FOR loop
#include <iostream>
void main()
{
int i;
for (i=0;i<=30;i++)
{
cout<<" "<<"i=";
cout<<i<<endl;
}
}25
Unit: 5// Program-13 to print natural numbers from 1 to 30 using
WHILE loop
#include<iostream>
void main()
{
int a=1;
while(a<=30)
{
cout<<a<<endl;
a++;
}
}
26
Unit: 5// Program-14 to print natural numbers from 1 to 30 using
DO WHILE loop
#include<iostream>
void main()
{
int a=1;
do
{
cout<<a<<endl;
a++;
}
while(a<=30);
}27
Unit: 5//Program -15 to display first 10 Odd numbers using FOR loop
#include <iostream>
void main()
{
int i;
for (i=1;i<=20;i=i+2)
cout<<" i="<<i<<endl;
}
28
Unit: 5//Program-17 to display first 10 Odd numbers using
WHILE loop
#include<iostream>
void main()
{
int a=1;
while(a<=20)
{
cout<<a<<endl;
a=a+2;
}
}
29
Unit: 5//Program-18 to display first 10 Odd numbers using
DO WHILE loop
#include<iostream>
void main()
{
int a=1;
do
{
cout<<a<<endl;
a=a+2;
}
while(a<=20);
}30
Unit: 5//Program-19 to find the Factorial of Number using do while loop
#include<iostream>
void main()
{
int n,i=1,fact=1;
cout<<" enter the number ";
cin>>n;
if(n>=0)
{
do
{
fact=fact*i;
i++;
}31
Unit: 5…..
while(i<=n);
cout<<"fact="<<fact<<"\n";
}}
32
Unit: 5Check Your Programming Skills:
Write a C++ program to display first 10 even numbers using
For loop? Write a C++ program to display first 10 even numbers using
WHILE loop? Write a C++ program to display first 10 even numbers using
DO WHILE loop? Write a C++ program to find the Factorial of Number using
For loop?
Write a C++ program to print all prime numbers between two
limits by using do while loop?
33
Unit: 6Objectives:To understand the concepts of nested loops
// Program-20 Program to display stars in a triangle shape
#include <iostream>
void main()
{
int i,j,k,n,m;
cout<<"Enter a number";
cin>>n;
m=n;
for(i=0;i<n;i++) // * * *
{ // * *
for(j=0;j<i;j++) // *
cout<<" ";
34
Unit: 6…..
for(k=0;k<m;k++)
cout<<" *";
cout<<endl;
m--;
}
}
35
Unit: 6Check Your Programming Skills: Write a C++ program to display different types of triangles
* * * * * * * * * * * *
* * * * * * * * * * * *
* * * * * * * * * * * *
* * * * * * * * * * * *
* * * * * * * * * * * * Write a C++ program to display following patterns?
* * * * * * *
* * * * * * * * *
* * * * * * * * * * *
* * * * * * * * *
*36
Unit: 7Objectives:To understand the concept of arrays
// Program-21 program to store 5 numbers in an array then
print them
#include<iostream>
void main()
{
int a[5],i;
for(i=0;i<5;i++)
{
cout<<"enter any Number :"<<endl;
cin>>a[i];
}
37
Unit: 7…..
cout<<"The Elements are as below : "<<endl;
for(i=0;i<5;i++)
{
cout<<a[i]<<endl;
}
}
38
Unit: 7// Program-23 program using arrays for checking Maximum
number and Minimum number among elements
#include <iostream>
void main()
{
int a[8],i,max,min;
cout<<"Enter 8 number:"<<endl;
for(i=0;i<8;i++)
cin>>a[i];
max=min=a[0];
39
Unit: 7…..
for(i=0;i<8;i++)
{ if (a[i]>max)
max=a[i];
if (a[i]<min)
min=a[i];
}
cout<<"Maximum number="<<max<<endl;
cout<<"Minimum number="<<min<<endl;
}
40
Unit: 7Check Your Programming Skills:
Write a C++ program to store 5 numbers in an array then print
them in reverse order? Write a C++ program to display following patterns?
41
Unit: 8Objectives:To implement the concept of function.
// Program-24 to Add two numbers using function
#include <iostream>
int add(int x, int y);
void main()
{
int a, b;
cout<<" Enter value of a ";
cin>>a;
cout<<" Enter value of b ";
cin>>b;
add(a,b);
}
42
Unit: 8…..
int add(int x, int y)
{
int res;
res = x+y;
cout<<" Sum = "<<res<<endl;
return res;
}
43
Unit: 8// Program-25 to find the factorial of a number by using function
#include<iostream>
int fact(int);
void main()
{
int x,f;
cout<<"enter the number";
cin>>x;
f=fact(x);
cout<<"The factorial"<<f;
}
44
Unit: 8….
int fact(int a)
{
int i,f=1;
for(i=1;i<=a;i++)
f=f*i;
return f;
}
45
Unit: 8Check Your Programming Skills:
Write a C++ program to calculate difference of two numbers by
using functions? Write a C++ program to calculate the Multiplication of two
numbers by using functions? Write a C++ program to calculate the square of any integer by
using functions? Write a C++ program to calculate the square root of any integer
by using functions?
46
top related