Upcoming SlideShare
×

# Lab 1

593

Published on

0 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

• Be the first to like this

Views
Total Views
593
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
6
0
Likes
0
Embeds 0
No embeds

No notes for slide

### Lab 1

1. 1. Basic of C++ Exercise Lab 1 Object Oriented Programming with C++
2. 2. Debugging Exercises <ul><li>Identify the error in the following program </li></ul><ul><li>#include <iostream.h> </li></ul><ul><li>void main() </li></ul><ul><li>{ </li></ul><ul><li>int I = 0; </li></ul><ul><li>I = I + 1; </li></ul><ul><li>cout << I << “ “ ; </li></ul><ul><li>/* comment * // I = I + 1; </li></ul><ul><li>cout << I; </li></ul><ul><li>} </li></ul>
3. 3. <ul><li>2. </li></ul><ul><li>#include <iostream.h> </li></ul><ul><li>void main() </li></ul><ul><li>{ </li></ul><ul><li>short I = 2500 , j = 3000; </li></ul><ul><li>cout >> “I + j = “ >> - ( I + j); </li></ul><ul><li>} </li></ul>
4. 4. <ul><li>3. </li></ul><ul><li>#include <iostream.h> </li></ul><ul><li>void main() </li></ul><ul><li>{ </li></ul><ul><li>int I = 10, j = 5 ; </li></ul><ul><li>int modResult = 0 ; </li></ul><ul><li>int divResult = 0; </li></ul><ul><li>modResult = I % j; </li></ul><ul><li>cout << modResult << “ “; </li></ul><ul><li>divResult = i/modResult; </li></ul><ul><li>cout << divResult; </li></ul><ul><li>} </li></ul>
5. 5. <ul><li>4. Find error if any </li></ul><ul><ul><li>cout << “x=“ x; </li></ul></ul><ul><ul><li>m = 5; //n=10; // s = m + n; </li></ul></ul><ul><ul><li>cin >> x ; >>y; </li></ul></ul><ul><ul><li>cout << “Name” << name; </li></ul></ul><ul><ul><li>cout << “Enter value:” ; cin >> x; </li></ul></ul><ul><ul><li>/* Addition */ z = x + y ; </li></ul></ul>
6. 6. Programming Exercises <ul><li>Write a Program to display the following output using a single cout statement </li></ul><ul><ul><ul><ul><li>Maths = 90 </li></ul></ul></ul></ul><ul><ul><ul><ul><li>Physics = 77 </li></ul></ul></ul></ul><ul><ul><ul><ul><li>Chemistry = 69 </li></ul></ul></ul></ul><ul><li>2. WAP to read two numbers from the keyboard and display the largest value on the screen </li></ul>
7. 7. <ul><li>3. WAP to input an integer value from keyboard and display on screen “WELL DONE” that many times. </li></ul><ul><li>4. WAP to read the values of a , b and c and display the value of x, where </li></ul><ul><li>x = a / b – c </li></ul><ul><li>test your program for the following values: </li></ul><ul><li>(a) a = 250, b = 85, c = 25 </li></ul><ul><li>(b) a = 300, b = 70, c = 70 </li></ul>
8. 8. <ul><li>5. WAP that will ask for a temperature in Fahrenheit and display it in Celsius. </li></ul><ul><li>1 Celsius = 33.8 Fahrenheit </li></ul><ul><li>C = (F – 32) x 5/9 </li></ul><ul><li>F = C x 9/5 + 32 </li></ul><ul><li>6. Redo Program 5 using a class called temp and member functions. </li></ul>
9. 9. Finished
1. #### A particular slide catching your eye?

Clipping is a handy way to collect important slides you want to go back to later.