55
Appendix Lab Manual for Programming Skills 1

Appendix Lab Manual for Programming Skills

  • Upload
    daw

  • View
    21

  • Download
    0

Embed Size (px)

DESCRIPTION

Appendix Lab Manual for Programming Skills. How to work with VC++. C++ PROGRAMING. To Make C++ program? File  New  win 2 console application  write project name  OK  Finish  OK OR   File  New c++ source File  write File name  OK. - PowerPoint PPT Presentation

Citation preview

Page 1: Appendix Lab Manual for Programming Skills

AppendixLab Manual for

Programming Skills

1

Page 2: Appendix Lab Manual for Programming Skills

How to work with VC++

2

Page 3: Appendix Lab Manual for Programming Skills

C++ PROGRAMING To Make C++ program?

File New win 2 console application

write project name OK Finish OK

OR   File New c++ source File

write File name OK

3

Page 4: Appendix Lab Manual for Programming Skills

Start Page in Visual C++ 2008 Express Edition.

Start Page tab

New Project tab

Hidden windows

Start Page links

4

Page 5: Appendix Lab Manual for Programming Skills

New Project dialog.

5Visual C++ Win32 Console Application (selected)

Template types

Description of selected project template(provided by Visual Studio)

Type in the project name

Page 6: Appendix Lab Manual for Programming Skills

Win32 Application Wizard Application Settings dialog.

6

Page 7: Appendix Lab Manual for Programming Skills

Solution Explorer.

7Solution Explorer with

an open projectNew tab displaying

Welcome.cpp source code

Welcome.cpp in the Source Filesfolder of the Welcome project

Page 8: Appendix Lab Manual for Programming Skills

Standard toolbar in Visual Studio.

8

NewProject

Open File Save All Copy Undo

Navigatebackward

Start

SolutionConfigurations

AddItem

Save Cut Paste Navigateforward

SolutionPlatforms

Find inFiles

Find SolutionExplorer

Propertieswindow

Toolboxwindow

Commandwindow

Objectbrowser

StartPage

Redo

Page 9: Appendix Lab Manual for Programming Skills

C++ PROGRAMING To Compile the C++ program?

  Build Compile.cpp select compile icon from the menu bar or press CTRL + F7

9

Page 10: Appendix Lab Manual for Programming Skills

C++ PROGRAMING To Execute the C++ program?

1-Bulid Execute .exe

2- select Execute icon from the menu bar

3-press CTRL + F5

10

Page 11: Appendix Lab Manual for Programming Skills

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 */ 11

Page 12: Appendix Lab Manual for Programming Skills

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.h> //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

12

Page 13: Appendix Lab Manual for Programming Skills

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

13

Page 14: Appendix Lab Manual for Programming Skills

Unit: 1//PROGRAM-2 to demonstrate cin cout (int, float,char)...#include<iostream.h>

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;

}

14

Page 15: Appendix Lab Manual for Programming Skills

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

15

Page 16: Appendix Lab Manual for Programming Skills

Unit: 1//PROGRAM-3 to find Sum and Average of two numbers.

#include<iostream.h>

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;

}

16

Page 17: Appendix Lab Manual for Programming Skills

Unit: 1//PROGRAM-4 to find Sum and Average of three numbers.

#include<iostream.h>

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;

}

17

Page 18: Appendix Lab Manual for Programming Skills

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?

18

Page 19: Appendix Lab Manual for Programming Skills

Unit: 2Objectives: To implement the concept of operators

// PROGRAM-5 to find area of a circle.

#include<iostream.h>

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;

}

19

Page 20: Appendix Lab Manual for Programming Skills

Unit: 2//Program -6 to display Pay slip of an employee

#include<iostream.h>

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;20

Page 21: Appendix Lab Manual for Programming Skills

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;

}

21

Page 22: Appendix Lab Manual for Programming Skills

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?

22

Page 23: Appendix Lab Manual for Programming Skills

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.h>

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";

}23

Page 24: Appendix Lab Manual for Programming Skills

Unit: 3//Program -8 to find number is ODD OR EVEN

#include<iostream.h>

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";

}

24

Page 25: Appendix Lab Manual for Programming Skills

Unit: 3//Program -9 to find the Grade of students

#include<iostream.h>

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';

25

Page 26: Appendix Lab Manual for Programming Skills

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;

 

}

26

Page 27: Appendix Lab Manual for Programming Skills

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?

27

Page 28: Appendix Lab Manual for Programming Skills

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.h>

void main()

{

int x;

cout<<"Enter number"<<endl;

cin>>x;

switch(x)

{

case 1:

cout<<"Saturday"<<endl;

break;28

Page 29: Appendix Lab Manual for Programming Skills

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;29

Page 30: Appendix Lab Manual for Programming Skills

Unit: 4……

case 6:

cout<<"Thursday"<<endl;

break;

case 7:

cout<<"Friday"<<endl;

break;

default:

cout<<"Error"<<endl;

}

}

30

Page 31: Appendix Lab Manual for Programming Skills

Unit: 4// Program- 11 Menu driven program ( + , * , - , %) using

switch case statement

#include<iostream.h>

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;

31

Page 32: Appendix Lab Manual for Programming Skills

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;

} }

32

Page 33: Appendix Lab Manual for Programming Skills

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?

33

Page 34: Appendix Lab Manual for Programming Skills

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;

}

}34

Page 35: Appendix Lab Manual for Programming Skills

Unit: 5// Program-13 to print natural numbers from 1 to 30 using

WHILE loop

#include<iostream.h>

void main()

{

int a=1;

while(a<=30)

{

cout<<a<<endl;

a++;

}

}

35

Page 36: Appendix Lab Manual for Programming Skills

Unit: 5// Program-14 to print natural numbers from 1 to 30 using

DO WHILE loop

#include<iostream.h>

void main()

{

int a=1;

do

{

cout<<a<<endl;

a++;

}

while(a<=30);

}36

Page 37: Appendix Lab Manual for Programming Skills

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;

}

37

Page 38: Appendix Lab Manual for Programming Skills

Unit: 5//Program-17 to display first 10 Odd numbers using

WHILE loop

#include<iostream.h>

void main()

{

int a=1;

while(a<=20)

{

cout<<a<<endl;

a=a+2;

}

}

38

Page 39: Appendix Lab Manual for Programming Skills

Unit: 5//Program-18 to display first 10 Odd numbers using

DO WHILE loop

#include<iostream.h>

void main()

{

int a=1;

do

{

cout<<a<<endl;

a=a+2;

}

while(a<=20);

}39

Page 40: Appendix Lab Manual for Programming Skills

Unit: 5//Program-19 to find the Factorial of Number using do while loop

#include<iostream.h>

void main()

{

int n,i=1,fact=1;

cout<<" enter the number ";

cin>>n;

if(n>=0)

{

do

{

fact=fact*i;

i++;

}40

Page 41: Appendix Lab Manual for Programming Skills

Unit: 5…..

while(i<=n);

cout<<"fact="<<fact<<"\n";

}}

41

Page 42: Appendix Lab Manual for Programming Skills

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?

42

Page 43: Appendix Lab Manual for Programming Skills

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<<" ";

43

Page 44: Appendix Lab Manual for Programming Skills

Unit: 6…..

for(k=0;k<m;k++)

cout<<" *";

cout<<endl;

m--;

}

}

44

Page 45: Appendix Lab Manual for Programming Skills

Unit: 6Check Your Programming Skills: Write a C++ program to display different types of triangles

* * * * * * * * * * * *

* * * * * * * * * * * *

* * * * * * * * * * * *

* * * * * * * * * * * *

* * * * * * * * * * * * Write a C++ program to display following patterns?

* * * * * * *

* * * * * * * * *

* * * * * * * * * * *

* * * * * * * * *

*45

Page 46: Appendix Lab Manual for Programming Skills

Unit: 7Objectives:To understand the concept of arrays

// Program-21 program to store 5 numbers in an array then

print them

#include<iostream.h>

void main()

{

int a[5],i;

for(i=0;i<5;i++)

{

cout<<"enter any Number :"<<endl;

cin>>a[i];

}

46

Page 47: Appendix Lab Manual for Programming Skills

Unit: 7…..

cout<<"The Elements are as below : "<<endl;

for(i=0;i<5;i++)

{

cout<<a[i]<<endl;

}

}

47

Page 48: Appendix Lab Manual for Programming Skills

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];

48

Page 49: Appendix Lab Manual for Programming Skills

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;

}

49

Page 50: Appendix Lab Manual for Programming Skills

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?

50

Page 51: Appendix Lab Manual for Programming Skills

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);

}

51

Page 52: Appendix Lab Manual for Programming Skills

Unit: 8…..

int add(int x, int y)

{

int res;

res = x+y;

cout<<" Sum = "<<res<<endl;

return res;

}

52

Page 53: Appendix Lab Manual for Programming Skills

Unit: 8// Program-25 to find the factorial of a number by using function

#include<iostream.h>

int fact(int);

void main()

{

int x,f;

cout<<"enter the number";

cin>>x;

f=fact(x);

cout<<"The factorial"<<f;

}

53

Page 54: Appendix Lab Manual for Programming Skills

Unit: 8….

int fact(int a)

{

int i,f=1;

for(i=1;i<=a;i++)

f=f*i;

return f;

}

54

Page 55: Appendix Lab Manual for Programming Skills

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?

55