Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 240 Computer Programming 1

Similar presentations


Presentation on theme: "CS 240 Computer Programming 1"— Presentation transcript:

1 CS 240 Computer Programming 1
Variables

2 Which of the following is a correct C++ identifier:
Question 1 : Which of the following is a correct C++ identifier: SS N1 a$total2 D_D s-3 _ds

3 Which of the following is correctly formed constant of type integer?
Question 2 : Which of the following is correctly formed constant of type integer? 145 4.0 12.3 34 ‘8’ “9” 12,5

4 Declare the following using one statement:
Question 3 : Declare the following using one statement: int x; int y; int z; char a = ‘i’; char b; char c = ‘E’; int x , y , z ; char a = ‘i’ , b , c = ‘E’ ;

5 Write a C++ statement to do the following:
Question 4 : Write a C++ statement to do the following: a) Declare two variables of type character, each one is in a separate declaration statement. char a ; char b ;

6 Write a C++ statement to do the following:
Question 4 : Write a C++ statement to do the following: b) Declare two variables of type character and initialize them with the values $and ? respectively in the declaration. NOTE: use one declaration statement. char c = ‘$’ , d = ‘?’ ;

7 Write the following algebraic expressions as C++ expressions:
Question 5: Write the following algebraic expressions as C++ expressions: 𝑏2−4𝑎𝑐 b * 2 – 4 * a * c

8 Write the following algebraic expressions as C++ expressions:
Question 5: Write the following algebraic expressions as C++ expressions: 𝑤𝑙𝑥2−𝑤𝑥22 w * l * x * 2 – w * x * 22

9 Question 6: Each of the following assignment statement contains at least one error. Identify them: Delta=x(y+(3x+(z+15))) X=5=y+4

10 Question 7: Given the algebraic equation y=a 𝑥 3 +7 , which of the following, if andy are correct C++ statements for this equation? a. Y= a*x*x*x+7; b. Y=a*x*x*(x+7); c. Y=(a*x) * x*(x+7); d. Y=(a*x)*x*x+7;

11 Correct the errors in the following programs:
Question 8: Correct the errors in the following programs: #include<iostream>; using namespace std; int main(); { int x; y=2; z= 4; x=y+z; cout<<”x”; //print the integer x } #include<iostream> using namespace std; int main() { int x, y=2 , z=4; x=y+z; cout<<x; //print the integer x }

12 Correct the errors in the following programs:
Question 8: Correct the errors in the following programs: #include<iostream> using name space std; int main { char a=”$”; cout<<a; cin>>b; cout<<b, return o; #include<iostream> using name space std; int main ( ) { char a=‘$’ , b; cout<<a; cin>>b; cout<<b; return 0; }

13 What is the output by each of the following code fragment?
Question 9: What is the output by each of the following code fragment? int x=1; int main() { int x=3; cout<<x<<endl; cout<<::x<<endl; return 0; } The output : 3 1

14 What is the output by each of the following code fragment?
Question 9: What is the output by each of the following code fragment? int a=1; int b=-3; int c=2; b=a++; c+=--a+b++; cout<<a<<" "<<b<<" " <<c; The output :

15 Problem 1 Question Write a program that asks the user to input 2 numbers A and B, then exchange the values of A and B.

16 Problem 1 Answer

17 Problem 1 Answer

18 Problem 2 Question Write a program that reads in the length and the width of a rectangular yard. Your program should compute the time required (in minutes) to cut the grass at the rate of 2.3 square meters per a second.

19 Problem 2 Answer

20 Problem 2 Answer

21 Problem 3 Question Write a program that asks the user to type the price without tax of one kilogram of tomatoes, the number of kilograms you want to buy and the tax in percent units. The program must calculate the total price including taxes.

22 Problem 3 Answer

23 Problem 3 Answer


Download ppt "CS 240 Computer Programming 1"

Similar presentations


Ads by Google