Appendix Lab Manual for Programming Skills 1. Symbols used in Writing Programs { opening curly bracket } closing curly bracket # hash sign or number sign.

Slides:



Advertisements
Similar presentations
C++ Basics March 10th. A C++ program //if necessary include headers //#include void main() { //variable declaration //read values input from user //computation.
Advertisements

Functions in C++. Functions  Groups a number of program statements into a unit & gives it a name.  Is a complete and independent program.  Divides.
A program example is given below to input date and display on the screen by write a class ‘ date ‘ # include Class date { Private: Int y, m, d ; Publice.
Exercise 5.
What is the out put #include using namespace std; void main() { int i; for(i=1;i
Lecture 8 Sept 25, Till now ► I► I► I► Introduction to computers ► S► S► S► Simple Programs using basic concepts like variables and data types,
C++ Programming Language Day 1. What this course covers Day 1 – Structure of C++ program – Basic data types – Standard input, output streams – Selection.
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to C++ Programming Outline Introduction to C++ Programming A Simple Program: Printing a.
Help session - C++ Arranged by : IEEE – NIIT Student Chapter.
A Variable is symbolic name that can be given different values. Variables are stored in particular places in the computer ‘s memory. When a variable is.
1 2/6/1435 h Wednesday Lecture 8. 2 Q: What is a %(modulus) operator ? 1. % (modulus) operator computes the remainder resulting from integer division.
Selection Statements in C++ If Statement in C++ Semantics: These statements have the same meaning as in the algorithmic language. 2- Two way selection:
More on Input Output Input Stream : A sequence of characters from an input device (like the keyboard) to the computer (the program running). Output Stream.
M. Taimoor Khan #include void main() { //This is my first C++ Program /* This program will display a string message on.
C++ Tutorial Hany Samuel and Douglas Wilhelm Harder Department of Electrical and Computer Engineering University of Waterloo Copyright © 2006 by Douglas.
Perimeter = 2*(length+width)
1 CS 1430: Programming in C++. 2 IF Statement if (cond) statement //Next statement if (cond) { statement1 statement2 … } //Next statement.
Course Title: Introduction to C++ Course Instructor: ADEEL ANJUM Chapter No: 01 1 BY ADEEL ANJUM (MCS, CCNA,WEB DEVELOPER)
C++ Programming: Basic Elements of C++.
Programming Fundamentals Lecture 4. In the Previous Lecture Basic structure of C program Variables and Data types Operators ‘cout’ and ‘cin’ for output.
CHAPTER 7 DATA INPUT OUTPUT Prepared by: Lec. Ghader R. Kurdi.
Fundamental Programming: Fundamental Programming Introduction to C++
CHAPTER 8 CONTROL STRUCTURES Prepared by: Lec. Ghader R. Kurdi.
1 Three C++ Looping Statements Chapter 7 CSIS 10A.
Perform Calculations and Control Flow Telerik Software Academy Learning & Development Team.
Lecture #7 CONTROL STRUCTURE & FLOW CHARTS
Chapter 7 Selection Dept of Computer Engineering Khon Kaen University.
Chapter 6.  Control Structures are statements that are used to perform repetitive tasks and to make decisions within a program. Loop repeats a sequence.
CSC1201: Programming Language 2 Lecture 1 Level 2 Course Nouf Aljaffan (C) CSC 1201 Course at KSU1.
Control Structures (B) Topics to cover here: Sequencing in C++ language.
A first program 1. #include 2. using namespace std; 3. int main() { 4. cout
C++ Programming, Namiq Sultan1 Chapter 3 Expressions and Interactivity Namiq Sultan University of Duhok Department of Electrical and Computer Engineerin.
Message: "You are mature"
Control of flow We learned that default flow of instructions is sequential. Then, we learned how to control the flow using "if" and "switch." Now, we will.
Lecture 4 Function example. Example1 int max (int a, int b) { int c; if (a > b) c = a; else c = b; return (c); } void main ( ) {int x, y; cin>>x>>y; cout.
CHAPTER 10 ARRAYS AND FUNCTIONS Prepared by: Lec. Ghader Kurdi.
GE 211 Dr. Ahmed Telba. // compound assignment operators #include using namespace std; int main () { a =5 int a, b=3; a = b; a+=2; // equivalent to a=a+2.
REPETITION STATEMENTS - Part2 Structuring Input Loops Counter-Controlled Repetition Structure Sentinel-Controlled Repetition Structure eof()-Controlled.
Function User defined function is a code segment (block) that perform an specific action. Function Definition: Function Definition: Return_DT F_name (
CS1201: PROGRAMMING LANGUAGE 2 FUNCTIONS. OVERVIEW What is a Function? Function Prototype Vs Decleration Highlight Some Errors in Function Code Parameters.
Lecture 5: Expressions and Interactivity Professor: Dr. Miguel Alonso Jr. Fall 2008 CGS2423/COP1220.
Lecture 5 Computer programming -1-. Input \ Output statement 1- Input (cin) : Use to input data from keyboard. Example : cin >> age; 2- Output (cout):
Course Title Object Oriented Programming with C++ instructor ADEEL ANJUM Chapter No: 03 Conditional statement 1 BY ADEEL ANJUM (MSc-cs, CCNA,WEB DEVELOPER)
C++ Basics Programming. COMP104 Lecture 5 / Slide 2 Introduction to C++ l C is a programming language developed in the 1970s with the UNIX operating system.
Lecture 7 Computer Programming -1-. Conditional Statements 1- if Statement. 2- if ….. else Statement. 3- switch.
Appendix Lab Manual for Programming Skills 1. How to work with VC++ 2.
Control Structures Selection: else / if and switch Dr. Ahmed Telba.
 2003 Prentice Hall, Inc. All rights reserved. 1 Basic C++ Programming.
LESSON 2 Basic of C++.
Selection (if-then-else) Programming Has 3 Types of Control: Sequential (normal): Control of Execution Proceeds One after the Other Selection (if-then-else):
Lecture #8 SWITCH STATEMENT By Shahid Naseem (Lecturer)
Asif Nawaz University Institute of Information Technology, PMAS-AAUR Lecture 05: Object Oriented Programming:2014 Object-Oriented Programming in C++ Exception.
Switch statement For selecting one choice from a list of choices switch statement evaluates an expression to determine a value Match the value with one.
Computer Programming -1-
Basic concepts of C++ Presented by Prof. Satyajit De
Chapter 1.2 Introduction to C++ Programming
Functions in C ++ Subject: Programming Languages ​​for III year Topic: functions, member class.
Chapter 1.2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
Arrays Part-1 Armen Keshishian.
Intro to Programming Week # 4 Switch Statement Lecture # 7
Chapter 2.2 Control Structures (Iteration)
Lab 1 Introduction to C++.
Intro to Programming Week # 3 If-else Statement Lecture # 6
Compound Assignment Operators in C++
Function User defined function is a code segment (block) that perform an specific action. Function Definition: Return_DT F_name ( list of formal parameters)
Chapter 2.2 Control Structures (Iteration)
Introduction to Algorithms and Programming COMP151
Presentation transcript:

Appendix Lab 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: 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 //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: 1 Program Explanation #include 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 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 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 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: 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? 9

Unit: 2 Objectives: To implement the concept of operators // PROGRAM-5 to find area of a circle. #include 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 void main () { double GSal,NSal,ded,basic,da; const double Housing= , 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: 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? 13

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 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 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 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: 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? 18

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 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 void main() { int n1, n2; char op; cout > n1; cout > n2; cout > 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: 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? 24

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 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 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 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 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 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 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 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: 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? 33

Unit: 6 Objectives:To understand the concepts of nested loops // Program-20 Program to display stars in a triangle shape #include 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: 6 Check Your Programming Skills: Write a C++ program to display different types of triangles * * * * ** * * * ** * Write a C++ program to display following patterns? ** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 36

Unit: 7 Objectives:To understand the concept of arrays // Program-21 program to store 5 numbers in an array then print them #include 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 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: 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? 41

Unit: 8 Objectives:To implement the concept of function. // Program-24 to Add two numbers using function #include 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 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: 8 Check 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