please , i have exam in my college about c++

i have exam in my college in c++ and the problem that exam in english language
and i am from egypt
so i am not perfect in english
i can solve ,but main problem to understand the question
so , i hope you can help me
this is the exam of last year
this is not all the exam
i am just show what i can't understand from this question
help me i have exam after 3 days :(
so i will give you the questions , and please give me the answers

1-) state whether each of the following is true or false ,if false explain why
(i)the break statement is required in the default case of a switch selection structure to exit the structure properly

(ii)an expression containing the ||operator is true if either or both of its operands are true

(iii) if there are fewer intializers in an intializer list than the number of elements in the array , the remaining elements are intialized to be last value in the list intializers

(iv) an individual array element that passed to a function and modified in that function wii contain the modified value when the called fucntion completes excution

(v) a pointer that is declared to be of type void can be derefrenced

(vi) pointers of different types may be not be assigned to one anther with out a cast operation


question (2)

write a single c++ statement (or set of c++ statements )to accomplish each of the following :
(i) calculate the value of 8 raised to power 4 using function pow. print the result with a precision of 2 in a field width of 10 positions

(ii) the function header of smallest that take three integers x,y and z and returns with and integar

(iii)use a for structure to print the elements of array numbers using pointers\ subscript notation with nprt

(v) copy the string stored in array s1 into array s2

question (3)

trace the following code fragement showing the value of each variable each time it changes
int x,y,z x=y=z=30 x*=y+=z-=8 ;


question (4)

explain the difference between the following two uses of the indirection operator :
int*q = p ;
n = *q ;

(b)
what is the minimum numbers of iterations that a while loop could make and a do...while loop could make ?


I also do not understand the questions. For example let consider the first question

why (i)the break statement is required in the default case of a switch selection structure to exit the structure properly


In fact break is not required in the switch statement.:) C++ is not C# where absence of a break statement is considered as an error.
So you can write for example

1
2
3
4
5
switch ( expression )
{
   case 1: case 2: case 3:
      std::cout << "I am here!\n";
}

It is a valid switch statement. Or another example

1
2
3
4
5
6
7
8
switch ( expression )
{
   case 1: case 2: case 3:
      std::cout << "I am here!\n";
      break;
   default:
      std::cout << "Oh, neither number of 1, 2, 3 was obtained!\n";
}


As you see here break statement is absent in the default case because in any case the exit from the switch will be successful.

However it is better to insert break statement in the default case even if the default case is the last case of a swutch statement. In this case all cases do not depend on the order in which they are present and you can rearrange them without any bad cobsequencies for the program. For example


1
2
3
4
5
6
7
8
9
switch ( expression )
{
   default:
      std::cout << "Oh, neither number of 1, 2, 3 was obtained!\n";
      break;
   case 1: case 2: case 3:
      std::cout << "I am here!\n";
      break;
}


I think that I would not pass your exams, because I have no single-valued answers.:)
Last edited on
I like to start from the bottom:
4b: while is 0, do-while is 1.
4a: the first line defines a pointer to an integer, then points to the value that is pointed to by p. The second line sets n to the value pointed to by q.

3:
1
2
3
int x, y, z; // All values are undefined;
x = y = z = 30; // All values are 30. 
x *= y += z -= 8; // z = 22, then y = 52, then x = 1560 


2i) std::cout << std::setw(10) << std::setprecision(2) << std::pow(8.0,4);
2ii) int smallest(int x, int y, int z);
2iii)
Last edited on
This question

(ii)an expression containing the ||operator is true if either or both of its operands are true


can have single-valued answer.
(iii) if there are fewer intializers in an intializer list than the number of elements in the array , the remaining elements are intialized to be last value in the list intializers


C# does not allow to specify less initializers than there are elements in an array. As for C++ then I think you know the answer without my help.
I think that this question

(iv) an individual array element that passed to a function and modified in that function wii contain the modified value when the called fucntion completes excution


is formulated incorrectly. The result depends on how the element was passed to the function that is how the function parameter is declared. More over the individual element can be in turn an array.

Last edited on
vlad
this question
really i can't understand it
what it mean
if there are fewer intializers in an intializer list than the number of elements in the array , the remaining elements are intialized to be last value in the list intializers

These two questions

(v) a pointer that is declared to be of type void can be derefrenced

(vi) pointers of different types may be not be assigned to one anther with out a cast operation


are false. Why? It is you who shall know the answers.:)
This question is simple

question (3)

trace the following code fragement showing the value of each variable each time it changes
int x,y,z x=y=z=30 x*=y+=z-=8 ;


Assignment operators are executed from the right to the left
closed account (o3hC5Di1)
Hi there,

To clarify that question:

 
int a[5] = {1, 2, 3, 4, 5};


{1, 2, 3, 4, 5}; is the initializer list. The question asks you: what if there are less than 5 numbers in this list? You have declared the array to be of length 5 int a[5]. For example:

 
int a[5] = {1, 2, 3};


Would a[3] and a[4] be assigned a value of 3, as it is the last value in the list?

Hope that clears it up for you.

All the best,
NwN
vlaaaaaaaad
i need answers
no puzzle :(
The answer to this question

(v) copy the string stored in array s1 into array s2


you can find in this thread

http://www.cplusplus.com/forum/beginner/89410/
dnt worry...here is the ans of questions u were asked..i hope it will help u..


1-)

(i) false, break statement is not requried in default case
because default case is optional

(ii) || is called OR operator.it is used to evaluate two conditons.It produce true result if either condition is true.It produce false result if both conditions are false.

(v)the type of pointer variable and the type of variable it refers must b same.it restrict the use of a pointer variable to specific type of variables.A variable can store the address of any type of variable if the pointer is declared as void.The keyword 'void' is used as the data type of pointer as follows void *p;

(vi) false, void can store the memory address of any type of variable


Question (2)

(i) cout<<setw(10)<<setprecision(2)<<pow(4, 8)<<endl

(ii)int smallest(int x, int y, int z);

i'll tell u the ans of remaining q.s soon
People will not hand you answers... They will hand you hints until they see effort on your behalf to solve the problems on your own.

Please refer to how to ask questions the smart way: http://cplusplus.com/forum/beginner/1/
@amara waseem

1-)

(i) false, break statement is not requried in default case
because default case is optional


In my opinion the answer is logically inconsistent with the question. The question does not ask whether the default case is optional or not. It asks whether a break statement shall be present in the default case.
Last edited on
the qs is break is required in default case...


the default case is optional so when there is no need of default case then obviously there is no need of break n default case
got it?
u have idea about what is break and default case?
@amara waseem

the qs is break is required in default case...


the default case is optional so when there is no need of default case then obviously there is no need of break n default case
got it?


I still think that you do not understand the question. It is not important whether the default case is optional or not. There is said that if the default case is present then the break is required or not.


the break statement in each case is used to exit from switch body.it is executed only when the result of expression does not match with any case label.when the result of expressions matches with a case, corresponding statements are executed. break statement comes after these statements and the control exits from switch body.if break is not used,all case after the matching case, will be executed....
default appears at the end of all case..it is executed only when the result of expression does not match with any case.


when default case is present,break is not required

i hope it satisfy u

@amara waseem
default appears at the end of all case..it is executed only when the result of expression does not match with any case.


when default case is present,break is not required

i hope it satisfy u


If you would read my previous posts then you would see an example when the default case can be in any place of the switch, that is it can be for example the first case in the switch.

Also I have not understood why did you write all this text. It does not prove that your previous statement was not wrong.
Last edited on
Topic archived. No new replies allowed.