1 / 55

Appendix Lab Manual for Programming Skills

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.

daw
Télécharger la présentation

Appendix Lab Manual for Programming Skills

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Appendix Lab Manual for Programming Skills

  2. How to work with VC++

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

  4. StartPage in Visual C++ 2008 Express Edition. New Project tab Start Page tab Start Page links Hidden windows

  5. NewProject dialog. Template types Visual C++ Win32 Console Application (selected) Description of selected project template (provided by Visual Studio) Type in the project name

  6. Win32 Application Wizard Application Settings dialog.

  7. Solution Explorer. Solution Explorer with an open project New tab displaying Welcome.cpp source code Welcome.cpp in the Source Files folder of the Welcome project

  8. Standard toolbar in Visual Studio. Solution Configurations Navigate backward New Project Open File Save All Copy Undo Start Save Paste Redo Add Item Cut Navigate forward Properties window Toolbox window Command window Solution Platforms Find in Files Find Solution Explorer Object browser Start Page

  9. C++ PROGRAMING • To Compile the C++ program? • Build  Compile.cpp • select compile icon  from the menu bar or • press CTRL + F7

  10. C++ PROGRAMING • To Execute the C++ program? 1-Bulid  Execute .exe 2- select Execute icon  from the menu bar 3-press CTRL + F5

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

  12. Unit: 1 Objective: 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

  13. Unit: 1 Program 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

  14. 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; }

  15. Unit: 1 • Program Explanationcin >> 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

  16. 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; }

  17. 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; }

  18. Uint: 1 Check 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?

  19. Unit: 2 Objectives: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; }

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

  21. 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; }

  22. Unit: 2 Check 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?

  23. Unit: 3 Objectives: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"; }

  24. 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"; }

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

  26. 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; }

  27. Unit: 3 Check 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?

  28. Unit: 4 Objectives: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;

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

  30. Unit: 4 …… case 6: cout<<"Thursday"<<endl; break; case 7: cout<<"Friday"<<endl; break; default: cout<<"Error"<<endl; } }

  31. 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;

  32. 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; } }

  33. Unit: 4 Check 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?

  34. Unit: 5 Objectives: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; } }

  35. 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++; } }

  36. 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); }

  37. 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; }

  38. 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; } }

  39. 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); }

  40. 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++; }

  41. Unit: 5 ….. while(i<=n); cout<<"fact="<<fact<<"\n"; }}

  42. Unit: 5 Check 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?

  43. Unit: 6 Objectives: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<<" ";

  44. Unit: 6 ….. for(k=0;k<m;k++) cout<<" *"; cout<<endl; m--; } }

  45. Unit: 6 Check Your Programming Skills: • Write a C++ program to display different types of triangles * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * • Write a C++ program to display following patterns? * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

  46. Unit: 7 Objectives: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]; }

  47. Unit: 7 ….. cout<<"The Elements are as below : "<<endl; for(i=0;i<5;i++) { cout<<a[i]<<endl; } }

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

  49. 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; }

  50. Unit: 7 Check 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?

More Related