C++ Help • What is the name of the function that is required to be in every prog
ID: 3836294 • Letter: C
Question
C++ Help
• What is the name of the function that is required to be in every program and tells the operating system where to start executing your code?
• Match the header file to the description of the functionality that it brings into your program.
Standard I/O
[ Choose ] string iostream fstream iomanip cstdlib or strlib.h
I/O Stream manipulators
[ Choose ] string iostream fstream iomanip cstdlib or strlib.h
String types and associated functions
[ Choose ] string iostream fstream iomanip cstdlib or strlib.h
File input and output
[ Choose ] string iostream fstream iomanip cstdlib or strlib.h
C utility functions such as rand(), srand()
[ Choose ] string iostream fstream iomanip cstdlib or strlib.h
• What value is stored in num after these statements execute?
double a = 11.0;
double b = 4.0;
int num = a/b;
• You are about to execute the statement at line 57:
Given these constants:
const int CARBON_MONOXIDE = 1;
const int HYDROCARBON = 2;
const int NITROGEN_OXIDE = 3;
const int NONMETHANE_HYDROCARBON = 4;
And this input:
After line 57 executes, which statement will be executed next?
• Given these constants:
const int FIRST_STAGE_MILEAGE = 50000;
const int CARBON_MONOXIDE = 1;
const int HYDROCARBON = 2;
const int NITROGEN_OXIDE = 3;
const int NONMETHANE_HYDROCARBON = 4;
const double CARBON_MONOXIDE_ALLOWED1 = 3.4;
const double CARBON_MONOXIDE_ALLOWED2 = 4.2;
const double HYDROCARBON_ALLOWED1 = 0.31;
const double HYDROCARBON_ALLOWED2 = 0.39;
const double NITROGEN_OXIDE_ALLOWED1 = 0.4;
const double NITROGEN_OXIDE_ALLOWED2= 0.5;
const double NONMETHANE_HYDROCARBON_ALLOWED1 = 0.25;
const double NONMETHANE_HYDROCARBON_ALLOWED2 = 0.31;
and these current values:
When execution transfers to this function, what will be the values of the arguments?
• You need to write a program that uses the speed of light in a vacuum (299792458 meters per second).
Realizing that this is a very large value, you run this code to see how large a value you can store as an int, a long int, a double, and a long double.
What further information about the problem your program will be built to solve do you need in order to chose an appropriate type to store a constant of this size?
• After learning more about the problem in the previous question, you decided to use a double to store the speed of light in a vacuum.
Show the statement needed to define a double constant to hold the value. Use the convention of all capital letters to define your constant name.
• You have an array that uses the following to set its size:
const int SIZEOF_DATA = 99;
The first valid index of the array is , the last valid index of the array is .
• What is a user-defined data type that allows you to group related variables together?
• What does it mean to say that arrays are always passed to a function by reference?
• This term means the range of statements where a variable can be used.
• Write a prototype for a function named sort that takes an integer array and an integer value (arr and max) representing the max index in the array and returns nothing. (Don't write the body of the function, just show the prototype.)
• Write a prototype for a function named swap that takes 2 integers (num1 and num2) as reference parameters and returns the maximum of the two integers. (Don't write the body of the function, just show the prototype.)
Show the values of array k after the above code executes:
, , ,
• Indicate what the logic error is in the following code and show how to fix it.
if (pH < 3)
cout << "Solution is very acidic" << endl;
else if (pH >= 3 && pH < 7)
cout << "Solution is acidic" << endl;
else if (pH == 7)
cout << "Solution is neutral" << endl;
else if (pH > 7 && pH < 12)
cout << "Solution is alkaline" << endl;
else if (pH > 12)
cout << "Solution is very alkaline" << endl;
else
cout << "Invalid pH value" << endl;
• What is the output of the following code?
bool b = -1;
cout << b << endl;
• You have the following definition:
struct Box
{
int height;
int width;
int length;
};
and variable declaration:
Box box1;
Fill in the operator needed here to access the height field.
box1 height
• The purpose of this function is to return the maximum value of a set of numbers in a file.
Complete the body of the loop. Do not define any other variables.
int getMax ()
{
int val;
int currentMax = 0;
ifstream infile("numbers.txt", ios::in);
if (! infile.is_open())
return -1;
while (infile >> num)
{
// show the code that goes here
}
return currentMax;
}
• How many times will the body of this loop execute?
int num = 4;
while (num < 0)
{
cout << num << endl;
num = num -1;
}
• What is the effect of the following code:
temp = 0;
for (i = 1; i < MAX; i++)
{
if (arr[i] > arr[0])
temp++;
}
• Which statements are true regarding the result of evaluating (a && b)?
• Which statements are true regarding the result of evaluating (a || b)?
• is a data type that has similar functionality to an array except that you do not need to know in advance how many positions are needed.
• What method do you use to determine how many items a vector currently has the potential to hold?
• When you define a structure, you are defining a new data type.
60Explanation / Answer
[1] What value is stored in num after these statements execute
double a = 11.0;
double b = 4.0;
int num = a/b;
Soluation : error: incompatible types: possible lossy conversion from double to int
[2]
Indicate what the logic error is in the following code and show how to fix it.
if (pH < 3)
cout << "Solution is very acidic" << endl;
else if (pH >= 3 && pH < 7)
cout << "Solution is acidic" << endl;
else if (pH == 7)
cout << "Solution is neutral" << endl;
else if (pH > 7 && pH < 12)
cout << "Solution is alkaline" << endl;
else if (pH > 12)
cout << "Solution is very alkaline" << endl;
else
cout << "Invalid pH value" << endl;
Sol: NO Error
[3]
What is the output of the following code?
bool b = -1;
cout << b << endl;
Solution : (B)--> 1
[4] When you define a structure, you are defining a new data type.
TRUE
[5] What method do you use to determine how many items a vector currently has the potential to hold?
capacity()
[6] Which statements are true regarding the result of evaluating (a || b)?
(A) It will evaluate to true if either a or b are true
[7] Which statements are true regarding the result of evaluating (a && b)?
(C) It will evaluate to true if both a and b are true
[8]
How many times will the body of this loop execute?
int num = 4;
while (num < 0)
{
cout << num << endl;
num = num -1;
}
OUTPUT : 4
3
2
1
Total 4 Time
[9]
What is the effect of the following code:
temp = 0;
for (i = 1; i < MAX; i++)
{
if (arr[i] > arr[0])
temp++;
}
(B) counts the number of elements of the array greater than its initial element
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.