Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can you please help me to find correct answer of below questions with explainati

ID: 672869 • Letter: C

Question

Can you please help me to find correct answer of below questions with explaination.?

Q.1 What is the bit pattern in data after the following statements execute?
unsigned int data = 10;
data = data | 0x0B;
data = data << 1;

0x314

0x154

0x342

0x156

Q.2 The code below computes the length of a C-style string. What should the value of FLAG be?

char name[20]= "Lancilot";

int length=0;

while(name[length] != FLAG)

{

length = length+1;

}

cout << length << endl;

‘’

20

NULL

0

Q.3 Given the following code fragment, what is the data type of thisStudent?
struct student
{
string name;
double gpa;
};
student thisStudent;

String

const pointer to student

student

double

Q.4 Given the code below,
struct student
{
string name;
double gpa;
};
which statement declares an array of 10 students, called myClass?

A.const int N=10; struct student x[N];

B.const int N=10; struct myClass students[N];

C.int N=10; struct student myClass[N];

D.const int N=10; struct student myClass[N];

D.

Q.5 What is the data type of bullpen[3].era?
struct pitcher
{
string name;
double era;
};
pitcher p1;
pitcher bullpen[10];

A.String

B.Double

C.Pitcher

D.const pointer to pitcher

D.

Q.6 What is the output of the following code?
void func(int *x)
{
*x = *x * 3;
};
int main()
{
int x = 10;
func (&x) ;
cout << x << endl ;
}

A.20

B.30

C.10

D.5

Q.7 Identify the correct prototype for a function that receives an array of doubles, finds the position of the largest value in the array, and returns the position to the calling function.

A.void findPosition(double array[], int size, double * position);

B.void findPosition (double array[], int size, int * position);

C.double findPosition (double array[], int size);

D.All of the above

D.

Q.8 Which of the following functions is taking an array of MyStruct structures as a pass by value parameter?

A.void MyFunc( MyStruct data[ ] );

B.void MyFunc( MyStruct &data[ ] );

C.void MyFunc( MyStruct *data[ ] ) ;

D.Not allowed in C++

D.

Q.9 Assume you have a class, called Simple, that has two data members, ‘a’ and ‘b’, both of type int. What can be said about the function prototype given below? (Choose the best answer.)

Simple(int=0, int=0);

A.It is the prototype for the default constructor

B.It is the prototype for the 2-argument constructor.

C.It is both the 0-argument, and the 2-argument, constructor.

D.It is incorrect.

D.

Q.10 When organizing a program into three files (main, class implementation, and class header), where are user-defined data types declared?

A.main.cpp

B.class.cpp

C.class.h

D.main.h

D.

Q.11 A Distance class has two private members, ‘feet’, of type int, and ‘inches’, of type double. Which prototype correctly declares the copy constructor for such class?

A.Distance Distance(const Distance &);

B.Distance(const Distance &);

C.int Distance(int, double);

D.Distance(feet, inches);

D.

Q.12 What is the output of the following code snippet?
int *list = new int[5];
int *ptr;
for (int i = 0; i < 5; i ++)  
list [ i] = i+ 1;
ptr = list;
delete [ ] list;
cout << *ptr;

A.1

B.Address of list

C.Address of ptr

D.Error – ptr references memory that no longer belongs to the program

Q.13 Assume you have to write a class that makes use of dynamic memory allocation (the class needs to allocate and de-allocate memory). According to best practices, where would the keyword ‘delete’ be placed?

A.Classes are smart data types. The compiler takes care of calling new/delete

B.It is in the constructor.

C.It is in the destructor.

D.It is in a separate, dedicated function.

Explanation / Answer

2.

‘’

3.

const pointer to student

4.

D. const int N=10; struct student myClass[N]

5.

B. Double

6.

B.30

7.

B. void findPosition (double array[], int size, int * position);

8.

A. void MyFunc( MyStruct data[ ] );

9.

D. It is incorrect.

10.

D. main.h

11.

D. Distance(feet, inches);

12.

D. Error – ptr references memory that no longer belongs to the program

13.

C. It is in the destructor.