Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

- When would you use a static_cast syntax with a char variable? Please explain in detail. - When you enter a letter or any character

- When would you use a static_cast<> syntax with a char variable? Please explain in detail.

- When you enter a letter or any character for an int variable, does the input stream enter the failed state? How do you fix it so the program continues?

Please give all necessary explanations for failed state.

What is the syntax needed to fix the failed state?

Please give an example of the situation.

- The screen size of a TV is given by the length of the rectangular diagonal. Traditional TVs come in 4:3 ratio, that is, the ratio of length to width is 4 to 3. This means, if the length is x inches, then the width is (3/4)x. LCD TVs come in 16:9 ratio. Calculate the length and width of both TVs if the diagonal length is 42 inches.

Explain how you came up with the formula for the calculations.

What inferences did you make from the given information?

Present all calculations, clearly, in a detailed manner to attain the solution.

- Given the input:

46 A 49

and the C++ code:

int x = 10, y = 18;

char z = '*';

cin >> x >> y >> z;

cout << x << " " << y << " " << z << endl;

What is the output?

Please state any assumptions you may have made in the interpretation.

- Suppose that str1, str2, and str3 are string variables, and str1 = "Physics", str2 = "Computer Science", and str3 = "Biology".

Evaluate the following expressions as true or false. Justify your answers with evidence.

str1 >= str2

str1 != "physics"

str3 < str2

str2 >= "Chemistry"

- Suppose that overSpeed and fine are double variables. Write C++ if statements for the following conditions:

if 0 < overSpeed <= 5, the value assigned to fine is $20.00

else if 5 < overSpeed <= 10, the value assigned to fine is $75.00

else if 10 < overSpeed <= 15, the value assigned to fine is $150.00

else if overSpeed > 15, the value assigned to fine is $150.00 plus $20.00 per mile over 15

State and explain any assumptions you may have made to write these statements.

-The following program contains errors.

Correct them so that the program will run and output w = 21.

Please explain what was wrong and how you fixed it so it would work.

#include

using namespace std;

const int SECRET = 5

main ()

{

int

x, y, w, z;

z = 9;

if

z > 10

x = 12; y = 5, w = x + y + SECRET;

else

x = 12; y = 4, w = x + y + SECRET;

cout << "w = " << w << endl;

}

- Write a for statement to add all the multiples of 3 between 1 and 100.

Explain how the for statement works and how you calculated the multiples of 3.

-Consider the following code segments.

How many times will each of the following loops execute? Please explain each iteration

What is the output in each case?

x = 5; y = 50;

do

x = x + 10;

while (x < y);

cout << x << " " << y << endl;

x = 5; y = 20;

do

x = x + 2;

while (x >= y);

cout << x << " " << y << endl;

-

- Please analyze the given function and answer the questions below.

int f(int n, int s1, int s2)

{

int a = s1, b = s2, temp;

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

{

temp = b;

b += a;

a = temp;

}

return b;

}

What is the value of b for f(3, 2, 3)?

Explain how you arrived at your answer.

- Analyze the given function and answer the question below:

void f(int arr[], const int MAX, int start)

{

arr[0] = start;

for(int i = 1; i < MAX; i++)

{

arr[i] = arr[i-1] * start;

}

}

Is the following statement true?

f(arr, 5, 4) -> arr = {4, 8, 16, 32, 64} +1 for true

Explain how you know it is true. What is the value of the array after each iteration?

-

Consider the code below:

int myList[10];

for(int i = 1; i <= 10; i--)

myList[i] = [i];

Correct the following code so that it correctly sets the value of each element of myList to the index of the element.

Please list all the corrections you made.

-

You need to code a function with the following prototype:

bool isPrime(int num);

Write a function to satisfy the above prototype. It should check if num is prime and return true or false.

State any assumptions you may have made.

Explain your algorithm or how you checked if the number is prime.

- Given the declaration:

char str1[21];

char str2[21];

Write a C++ statement that stores "Sunny Day in str1.

Write a C++ statement that stores the length of str1 into the int variable length.

Write a C++ statement that copies the value of name into str2.

Write C++ code that outputs str1 if str1 is less than or equal to str2, and otherwise outputs str2.

- Struct Point {

int x;

int y;

};

Point points[10][10];

How do you access the x member at the 5th column and 6th row?

What assumptions did you make?

(Solution:

points[6][5].x worth 4

)

- You need to code a function with the following prototype:

int findMaximum(int arr[MAX]);

Write a function to satisfy the above prototype.

State any assumptions you may have made.

- Suppose that you have the following declarations:

int times[30][7];

int speed[15][7];

int trees[100][7];

int students[50][7];

Write the definition of the function print that can be used to output the contents of these arrays. Your function should take only one 2 dim array to achieve this task and be a void function.

Write the C++ statements that calls the function print to output the contents of the arrays times, speed, trees, and students

- Assume that you have the following definition of a struct:

struct partsType

{

string partName;

int partNum;

double price;

int quantitiesInStock;

};

Write a C++ code to initialize each component of inventory as follows: partName to null string, partNum to -1, price to 0.0, and quantitiesInStock to 0.

Write a C++ code that uses a loop to output the data stored in inventory. Assume that the variable length indicates the number of elements in inventory.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Put Your Data To Work 52 Tips And Techniques For Effectively Managing Your Database

Authors: Wes Trochlil

1st Edition

0880343079, 978-0880343077

More Books

Students also viewed these Databases questions