Question
Help neended. please help me answer this C++ exam review Exam 2 Review Section 1: Quickfire Questions 1. Assume the following declarations: int p =
Help neended. please help me answer this C++ exam review
Exam 2 Review
Section 1: Quickfire Questions
1. Assume the following declarations:
int p = 7;
int *x[3];
int y[3]= {5,9,2};
For each of the expressions, determine the data type of the left hand side (LHS) and right hand side (RHS) of the assignment and finally determine if the assignment is a legal one
Expression Data Type LHS Data Type RHS Legal? |
x[1] = &p; |
y[0]= *(x[1]); |
p = y[2]; |
y = x[1]; |
x[0] = y; |
2. Assume the following declaration:
char names [5][10] = {Google, Microsoft, Apple, IBM, Dell};
Determine the output of the following statements
a. cout << names[1];
b. cout << *(names + 2);
c. cout << *(*(names+1)+2);
d. cout << *names[3];
e. cout <<( names[0] + 2);
Section 2: Short Answer
1. Draw a memory diagram for the following program at the execution point indicated
void fun(int* x)
{
x[2] = x[1] = *x + 1;
x = new int[2];
//Draw state of memory here for m,n,o, and x
}
int main ()
{
int *m, *n, o;
m = &o;
o = 3;
n = new int[3];
n[0] = *m;
fun(n);
return 0;}
Section 2: Code Snippets:
const int NUM_STUDENTS = 24;
const int NUM_GRADES = 3;
int satScores[NUM_STUDENTS][NUM_GRADES];
Assume data in satScores is initialized with the data of 24
students who each took the SAT exactly 3 times.
Provide a snippet of code for each of the following:
Display what the average score was on the first try for all students. Output this to the screen nicely formatted.
Display the average SAT score for the 8th student? Output this to the screen nicely
formatted.
Display the student number who had the highest SAT score on the third try? Output this to the screen nicely formatted.
Display which student had the highest average (average in this case referring to the average score of all times the student took the SAT). Output the student number to the screen. You may assume there will be no ties between students.
Is it true that in the 2nd time taking the exam, all student performed better when
compared to the first try? Output an appropriate message depending on whether the
preceding is determined to be true or false.
Section 3: Code Snippets:
Provide a snippet of code to perform the following requirements.
Assume the following array has already been declared and initialized:
const int SIZE = 25;
int myData[SIZE];
//assume other code to store positive integers in myData
1. Find and print to the screen the largest value in the array.
2. Find and print to the screen the the index of the smallest value in
the array.
3. Print the elements of the array to the screen in reverse order (starting with the last
element of the array). Print only one element per line of output.
Section 4: Short Answer:
For the following questions, provide an appropriate array declaration. None of the following
questions should require more than one c++ statement.
1. Declare an array of type double to contain 15 elements.
2. Declare an array of type int to contain 4 elements initialized to 10, 13, 16, and 17
3. Declare an array of type int to contain 15 elements all initialized to 0.
4. Declare an array of floats to contain 10 elements with the first 3 initialized to 3.8, 3.9 and 3.7.
5. Dynamically allocate an array of 10 integers and populate it with integers.
6. Sort the above array using a selection sort
7. Do a binary search on the above array to determine if it contains the number 55.
8. Dynamically create a vector of strings. Add 5 strings of your choice to it.
9. Remove the last string in the above vector.
Section 5: Creating your own class definition
Write a program that contains the following functionality:
Create a Video class that contains the following attributes and functionality:
Name of the video (a string)
Price of the video (a double)
A constructor that receives the data for the attributes or defaults those attributes to reasonable values.
Sets and gets for the attributes
A display method that displays the attributes, nicely formatted with labels.
Write a main driver that completely tests the class by creating at least 4 Video objects. The driver should call all the sets and get methods and the display method.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started