0% found this document useful (0 votes)
20 views3 pages

Homework 1

ا

Uploaded by

b47qvp5vff
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views3 pages

Homework 1

ا

Uploaded by

b47qvp5vff
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Lusail University

College of Information Technology


Computer Programming, I_10075_202310,
Instructor: Professor Mohammad Alshraideh
Homework 1: (14 points)
1- Which of the following are valid C++ identifiers? And explain why if not.
(5 points)

Valid/Not Valid
a) firstC++Prog not valid because identifiers can't use the + sign
b) cin
valid
c) 3feetInAYard
not valid because it starts with a digit
d) _number
valid
e) CPP_Assignment
valid
f) Int
valid
g) Monthly Pay
not valid because you can't put space in identifiers
h) Jack’sHomework
not valid because you can't put ' in identifiers

i) first# not valid because you can't put # in identifiers

j) bonusAmount$ not valid because you can't put $ in identifiers


2. If int x = 10.5; int y = 7.6; double z = 4.5; and double w = 4;
evaluate each of the following statements, if possible. If it is not possible,
state the reason.(4 points)
Results
a. (x + y) % x
7
b. x % y + w
7
c. (z - y) / w
-0.625
d. (y + z) % x Not possible, because the results of (y + z) will be in double data type,
and % doesn't work with double data type.
e. (x % y) * z
13.5
f. x % y % 2
1
g. (x + y) % z Not possible, because z is a double data type, and the operation % doesn't
work with floating points.
h. (x % y + z) / w
1.875

Q3) Suppose you have the following declarations and statements. (2.5 points)
int x, int y;
double d;
char c1, c2;
cin>>x>>c1>>y>>d;
and you have the following input.
27,8196.2237
What is the output of the following:
Cout<<x<<y<<c1<<c2<<d>>endl;

Error
Q4) you have the following identifiers: (2.5 points)
int x=2.1, y=8, w;
double d=12;
bool b1 =x * 4 -y;
d= d -b1;
w= ++x + (y++) % 4;
What are the values held in x, y, d, and b1 after executing the above statements?

x= 3
y= 9
d= 12
b1= 0
w= 3

Good Luck

You might also like