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

(TCO 1) For the values given, what will c contain after executing the following?

ID: 3555381 • Letter: #

Question

(TCO 1) For the values given, what will c contain after executing the following?

int a = 9, b = 4, c = -2;
c *= ++a % b;

Answer= -4

(TCO 2) Which statement outputs a double value in a field of nine characters with three digits after the decimal point?

Answer= cout << setprecision(3) << setw(9) << 1.2345678;

(TCO 10) For readability, variable names should be

Answer = indicative of what value is being stored in the variable.

(TCO 3) What is the value of beta after the following code executes if the input is 5?

Int beta;

cin>> beta;

switch(beta)

{

case5:

beta +=5;

case1:

beta++;

case5:

beta +=5;

break;

case 4:

beta +=4;

}

Answer= 16

(TCO 4) How many times does the following loop body execute?

Int count=52

For(int i=26; i>=0; i=i-2)

{

cout<<count<<endl;

-- count;

}

Answer= 14

(TCO 8) Trying to access an array element beyond the end of the array can lead to an attempt to access an address outside your program's memory space which is a

Answer = Runtime error

(TCO 8) When a program is stopped at a breakpoint, you can use the debugger to

examine program variables.

change the value of program variables.

set new breakpoints or clear existing breakpoints.

All of the above

Answer = All of the above

(TCO 9) White box testing

Answer = requires knowledge of the structure of the program code

(TCO 9) When doing feature testing, _______.

Answer = a test case is based on how a correct solution to the problem would respond to given inputs

(TCO 5) It is necessary to pass by reference when a function

Answer = is returning more than one result.

(TCO 5) Arrays are always passed into a function by location because

Answer = it is much quicker to pass location information than to create a copy of the entire array which would be needed for pass by value.

(TCO 6) An array is a data type that contains _______.

a fixed number of elements

a set of values all of which are of the same type

values that must either be initialized when the array is declared or assigned at runtime

All of the above

Answer = All of the above

(TCO 5) Place function prototypes before main() to

Answer = avoid compilation errors.

(TCO 5) What is the output of the following code?

void func(int x[])

{

       x[0] = x[0] * 3;

       x[1] = x[1] * 3;

       x[2] = x[2] * 3;

}

int main()

{

       int x[] = { 1, 2, 3 };

       func(x);

       cout << x[0] << " " << x[1] << " "<< x[2] << endl;

}

Answer = 3 6 9

(TCO 5) The function overloading feature of C++ enables _______.

Answer = several functions to have the same name

(TCO 6) What is the range of valid subscripts for the following array?

double list[10];

Answer = 0 to 9

(TCO 6) Given the following array declaration, if the array is stored starting at address 1000, what is the output of the following statement? Assume the code is for a 32 bit processor such as a Pentium.

double data[25] = {0.0};
cout << &data[10] << endl;

Answer = 1080

(TCO 6) Given the following code which fills the array with values,

int X;

int data[100];

for (int i = 0;i<= X; i++)

{

            data[i] = i;

}

Answer = 99

(TCO 6) foo contains _______.

double foo[500] = {0.0};

Answer = 500 double value

(TCO 6) For the array declared below, what is the sum of list[2] and list[3]?

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

Answer = 7

(TCO 5) A variable declared within a block (inside curly brackets) is visible

Answer = from the point of declaration onward to the end of the block.

(TCO 7) A C-Style string which is not null terminated will

Answer = cause a run-time error when processed by the strcpy function.

(TCO 7) Which of the following functions would correctly copy C string s2 to C string s1?

Answer = strcpy(s1, s2) ;

(TCO 7) Given the following string variable, write a statement that would insert "interesting" before the wordexample
in str1.

string str1 = "Here is an example string";

Answer = str1.insert(11, "interesting ");

(TCO 7) Given the following string variable, write a statement that would locate the position of "string" in thestr1 variable and store the result in an int variable namedpos.

string str1 = "Here is an example string";

Answer = int pos = str1.find("string");

(TCO 7) Create an output format statement which would generate lines in the table which appear as shown below. The Employee Name Field displays an employee name contained in the name variable. YYY displays an integer value from the age variable which ranges from 1 thru 100 and should be right justified. XXXXX.XX displays a monetary value from the salary variable which ranges from 0.01 to 99999.99 and should also be right justified. Use the variables shown below in your output statements.

Employee Name Field------YYY----$XXXXX.XX

char name[25]; int age; double salary;

Answer =

cout << fixed << setprecision(2);
cout << left << setfill('-') << setw(25) << name << right << setw(3)
     << age << "----$"
<< setw(8) << salary << endl;

(TCO 6) Write a function called AnalyzeData. This function is passed a double array along with a parameter that indicates the number of elements in the array. It is also passed a double value. The function computes and returns the number of values in the array that are greater than this double value. Write a complete C++ function to do this operation. There is no cin or cout in this function. This is only a function, so there is no main routine here!

Answer =

int analyzeData(double
data[], int size, double
value)
{
     int count = 0;
     for(int i = 0; i < size; i++)
     {
           if(data[i] > value)
                count++;
     }
     return count;
}

(TCO 5) Write a function that takes inputs of yards and feet (whole numbers) and calculates and returns an output of the total number of miles (a floating-point value). There are 5280 feet per mile. There are 3 feet in a yard. Use appropriate parameter passing and return mechanisms. Use appropriate datatypes. For example, with inputs of 1760 yards and 1320 ft, the result would be 1.25 miles. Use proper code formatting techniques. Do not write a main routine. Your function does not do cin or cout.

Answer =

double toMiles(int
yards, int feet)
{
     double miles;
     feet += yards * 3;
     miles = feet / 5280.0;
     return miles;
}

(TCO 5) Write a function that converts an input of some integer number of inches into outputs of integer numbers of yards, feet, and inches. Do not write a main function. Your function does not do cin or cout. Your function will have four parameters. Make sure you use appropriate parameter passing techniques! Your function will be a void function. There are 12 inches in a foot, and 36 inches in a yard. For example, if the total number of inches input is 50, the results are 1 yard, 1 foot, and 2 inches.

Answer =

void from_inches(int
inches, int& yds, int& ft, int& in)
{
     yds = inches / 36;
     ft = (inches - yds * 36) / 12;
     in = inches - yds * 36 - ft * 12;
}

(TCO 7) Write a function which takes a C string as an input and counts the number of non-alphabetic characters in the C string. Non-alphabetic characters include anything outside the ranges 'a' thru 'z' and 'A' thru 'Z'. Do not count the null terminator. You are not allowed to use any other functions to do this. Do not write a main function. Your function does not do any cin or cout. Remember, C strings are terminated with the '' character. Make sure to properly format all your code.

Answer =

int nonAlpha(char
s[])
{
     int x = 0;
     int count = 0;
     while(s[x] != '')
     {
           char ch = s[x++];
           if((ch < 'a' || ch > 'z') && (ch < 'A' || ch > 'Z'))
           {
                count++;
           }
     }
     return count;
}

(TCO 7) Write a function which takes two string variables (not C strings) as inputs and compares them. If they are equal, the function should return 0. If the first string is less than the second string, return a negative number. If the firststring is greater than the second string, return a positive number. You are not allowed to use the compare method of the string data type. You must use the comparison operators. Do not write a main function. Your function does not do any cin or cout. Make sure to properly format all your code.

Answer =

int compare(string a, string b)
{
     if(a == b)
           return 0;
     else if(a < b)
           return -1;
     else
           return 1;
}

Explanation / Answer

(TCO 1) For the values given, what will c contain after executing the following?
int a = 9, b = 4, c = -2;
c *= ++a % b;

Corrrect option: -4

(TCO 2) Which statement outputs a double value in a field of nine characters with three digits after the decimal point?

Correct option:

cout << setprecision(3) << setw(9) << 1.2345678;

(TCO 10) For readability, variable names should be

Correct option:

indicative of what value is being stored in the variable.

(TCO 3) What is the value of beta after the following code executes if the input is 5?

Int beta;

cin>> beta;

switch(beta)

{

case5:

beta +=5;

case1:

beta++;

case5:

beta +=5;

break;

case 4:

beta +=4;

}

After execution of this code, the output is 16.

(TCO 4) How many times does the following loop body execute?

Int count=52;

For(int i=26; i>=0; i=i-2)

{

cout<<count<<endl;

-- count;

}

Correct option is 14.

(TCO 8) Trying to access an array element beyond the end of the array can lead to an attempt to access an address outside your program's memory space which is a

Correct option: Runtime error

(TCO 8) When a program is stopped at a breakpoint, you can use the debugger to

examine program variables.

change the value of program variables.

set new breakpoints or clear existing breakpoints.

All of the above

(TCO 9) White box testing

Correct option: requires knowledge of the structure of the program code

(TCO 9) When doing feature testing, _______.

Correct option : a test case is based on how a correct solution to the problem would respond to given inputs

(TCO 5) It is necessary to pass by reference when a function

Correct option: is returning more than one result.

(TCO 5) Arrays are always passed into a function by location because

Correct option: it is much quicker to pass location information than to create a copy of the entire array which would be needed for pass by value.

(TCO 6) An array is a data type that contains _______.

a fixed number of elements

a set of values all of which are of the same type

values that must either be initialized when the array is declared or assigned at runtime

All of the above

Correct option: All of the above

(TCO 5) Place function prototypes before main() to

Correct option: avoid compilation errors.

(TCO 5) What is the output of the following code?

void func(int x[])

{

       x[0] = x[0] * 3;

       x[1] = x[1] * 3;

       x[2] = x[2] * 3;

}

int main()

{

       int x[] = { 1, 2, 3 };

       func(x);

       cout << x[0] << " " << x[1] << " "<< x[2] << endl;

}

Output of the above code: 3 6 9

(TCO 5) The function overloading feature of C++ enables _______.

Correct option: several functions to have the same name

(TCO 6) What is the range of valid subscripts for the following array?

               double list[10];

The range of the double array: 0 to 9

(TCO 6) Given the following array declaration, if the array is stored starting at address 1000, what is the output of the following statement? Assume the code is for a 32 bit processor such as a Pentium.

double data[25] = {0.0};
cout << &data[10] << endl;

Correct option: Hexadecimal value will be displayed

(TCO 6) Given the following code which fills the array with values,

int X;

int data[100];

for (int i = 0;i<= X; i++)

{

            data[i] = i;

}

Correct option: Error will be dispalyed

(TCO 6) foo contains _______.

double foo[500] = {0.0};

Correct option: 0.0 is assigned to 500 locations.

(TCO 6) For the array declared below, what is the sum of list[2] and list[3]?

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

Correct Answer: 7

(TCO 5) A variable declared within a block (inside curly brackets) is visible

Correct option: from the point of declaration onward to the end of the block.

(TCO 7) A C-Style string which is not null terminated will

Correct option: cause a run-time error when processed by the strcpy function.

(TCO 7) Which of the following functions would correctly copy C string s2 to C string s1?

Correct option: strcpy(s1, s2) ;

(TCO 7) Given the following string variable, write a statement that would insert "interesting" before the wordexample
in str1.

string str1 = "Here is an example string";

Correct option: str1.insert(11, "interesting ");

(TCO 7) Given the following string variable, write a statement that would locate the position of "string" in thestr1 variable and store the result in an int variable namedpos.

string str1 = "Here is an example string";

Correct option: int pos = str1.find("string");

(TCO 7) Create an output format statement which would generate lines in the table which appear as shown below. The Employee Name Field displays an employee name contained in the name variable. YYY displays an integer value from the age variable which ranges from 1 thru 100 and should be right justified. XXXXX.XX displays a monetary value from the salary variable which ranges from 0.01 to 99999.99 and should also be right justified. Use the variables shown below in your output statements.

Employee Name Field------YYY----$XXXXX.XX

char name[25]; int age; double salary;

Correct option:

cout << fixed << setprecision(2);
cout << left << setfill('-') << setw(25) << name << right << setw(3)
     << age << "----$"
<< setw(8) << salary << endl;

(TCO 6) Write a function called AnalyzeData. This function is passed a double array along with a parameter that indicates the number of elements in the array. It is also passed a double value. The function computes and returns the number of values in the array that are greater than this double value. Write a complete C++ function to do this operation. There is no cin or cout in this function. This is only a function, so there is no main routine here!

Correct option:

int analyzeData(double data[], int size, double value)
{
     int count = 0;
     for(int i = 0; i < size; i++)
     {
           if(data[i] > value)
                count++;
     }
     return count;
}

Remaining answers are correct.