Lab #1

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Lab # 1

At the end of this Lab. you will be able to learn; 1. 2. 3. 4. 5. 6. Header Files Stream Insertion Operator Stream Extraction Operator C++ Statements Assignment Statements Escape Sequences

Lab practice #1 Printing text line


#include <iostream.h> int main() { cout << "Welcome to C++"; }

Holding Output on Screen


#include <iostream.h> #include<conio.h> int main() { cout << "Welcome to C++!\n"; getch(); }

Lab Practice #2 Calculate the sum of two integers


// Addition program #include <iostream.h> #include <conio.h> int main() { int integer1; // first number to be input by user int integer2; // second number to be input by user int sum; // variable in which sum will be stored

cout << "Enter first integer\n"; // prompt cin >> integer1; // read an integer

cout << "Enter second integer\n"; // prompt cin >> integer2; // read an integer

sum = integer1 + integer2; // assign result to sum cout << "Sum is " << sum << std::endl; // print sum getch(); // indicate that program ended successfully } // end function main

Lab Exercise #1:


Write a program that asks the user to enter two numbers obtains the two numbers from the user and prints the sum, product, difference and division of the two numbers.

Lab Exercise #2:


Write a program that prints a box and a diamond #include <iostream.h> #include<conio.h> int main() { cout<<"**********\n"; cout<<"* *\n"; cout<<"* *\n"; cout<<"* *\n"; cout<<"* *\n"; cout<<"* *\n"; cout<<"* *\n"; cout<<"**********\n"; getch(); } #include <iostream.h> #include<conio.h> int main() { cout<<" *\n"; cout<<" * *\n"; cout<<" * *\n"; cout<<" * *\n"; cout<<"* *\n"; cout<<" * *\n"; cout<<" * *\n"; cout<<" * *\n"; cout<<" *\n"; getch(); } Wirte a program that prints an arrow:
* *** ***** * * * * *

Lab Practice #3
# include <iostream.h> # include <conio.h> int main() { int grade; cout<<"Name: \"xyz\""; cout<<"\nRoll Number: \"123\""; cout<<"\nsubject: \"C++ programming\""; cout<<"\nenter your grade :"; cin>>grade; if (grade>=90) cout<<"A"; if (grade>=80) cout<<"B"; if (grade>=70) cout<<"C"; if (grade>=60) cout<<"D"; if (grade<60) cout<<"F"; getch(); }

You might also like