QUESTION 1
Given two double variables named x and y, which of the following statements could you use to initialize both variables to a value of 0.0?
| a. |
x | y = 0.0; |
|
| b. |
x = y = 0.0; |
|
| c. |
x, y = 0.0; |
|
| d. |
none of the above |
1 points
QUESTION 2
When you use a range-based for loop with a vector, you
| a. |
can avoid out of bounds access |
|
| b. |
must still use a counter variable |
|
| c. |
can process a specified range of elements |
|
| d. |
must still use the subscript operator |
1 points
QUESTION 3
Which of the following statements would you use to creat a vector of ints named ages with an initial size of 20 elements?
| a. |
vector<ages> int(20); |
|
| b. |
vector<20> ages(int); |
|
| c. |
vector<20> int(ages); |
|
| d. |
vector<int> ages(20); |
1 points
QUESTION 4
Which of the following statements could you use to assign a value to the first element of a vector of doubles named wages?
| a. |
wages<1> = 258.25; |
|
| b. |
wages[1] = 258.25; |
|
| c. |
wages<0> = 258.25; |
|
| d. |
wages[0] = 258.25; |
1 points
QUESTION 5
Which of the following statements is not true about a string?
| a. |
With C++98 and later, you can use the string class of the C++ standard library to work with strings. |
|
| b. |
You can use the subscript operator to access the individual characters of a string. |
|
| c. |
You can use a ranged-based for loop to work with the characters in a string. |
|
| d. |
If you compare one string with another string, the default comparison is case-insensitive. |
1 points
QUESTION 6
Which of the following is a difference between the float and double data types?
| a. |
float contains a floating-point number and double contains a decimal number |
|
| b. |
float can have up to 7 significant digits and double can have up to 16 |
|
| c. |
float numbers are expressed using scientific notation and double numbers are expressed using fixed-point notation |
|
| d. |
float can provide only for positive numbers and double can provide for both positive and negative |
1 points
QUESTION 7
Which of these names follows the naming conventions for constants presented in this chapter?
| a. |
WeeksInYear |
|
| b. |
WEEKS_IN_YEAR |
|
| c. |
Weeks_In_Year |
|
| d. |
weeks_in_year |
1 points
QUESTION 8
What is the value of the variable named password after the
following code is executed?
string password = "openSesame";
password[0] = toupper(password[0]);
for (int i = 1; i < password.size(); ++i) {
password[i] = tolower(password[i]);
}
password.push_back('!');
| a. |
Opensesame! |
|
| b. |
Opensesame |
|
| c. |
opensesame |
|
| d. |
opensesame! |
1 points
QUESTION 9
What is the value of the variable named street after the
following code is executed?
string address = "123 Main St., Somewhere, CA 93299";
string street = "";
int index1 = address.find('.');
int index2 = address.find(',');
if (index1 > -1 && index2 > -1) {
if (index1 < index2) {
street =
address.substr(0, index1);
}
else {
street =
address.substr(0, index2);
}
}
| a. |
"123 Main St." |
|
| b. |
"123 Main St" |
|
| c. |
"" |
|
| d. |
"123 Main St.," |
1 points
QUESTION 10
If the result of an arithmetic expression is assigned to a variable with a type that could cause a loss of data when the conversion is performed, you should
| a. |
explicitly cast the data so an error doesn’t occur at runtime |
|
| b. |
modify the code so it uses a data type that won’t cause a loss of data |
|
| c. |
add code that checks for any errors that may be caused by the conversion |
|
| d. |
explicitly cast the data to indicate that you intend to perform the conversion |
QUESTION 1) c
// Screenshot of the code

// Sample output

// code to copy
#include <iostream>
using namespace std;
int main() {
double x,y=0.0;
cout<<"x:"<<x<<" y:"<<y;
return 0;
}
QUESTION 2) c
Explanation:
can process a specified range of elements
example:
for(int i=0; i < vector.size(); i++){
vector[i].doSomething();
}
QUESTION 3) d

Explanation:
vector<int> ages(20);
QUESTION 4) d
// Screenshot of the code

// Sample output

// code to copy
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<int> wages(20);
wages[0] = 258.25;
cout<<wages[0];
return 0;
}
QUESTION 5) a
Explanation:
With C++98 and later, you can use the string class of the C++ standard library to work with strings.
QUESTION 6) b
Explanation:
float can have up to 7 significant digits and double can have up to 16
QUESTION 7) b
Explanation:
Constants are declared in capital letters and underscores as WEEKS_IN_YEAR.
QUESTION 8 ) a
// Screenshot of the code

// Sample output

// code to copy
#include <iostream>
using namespace std;
int main() {
string password = "openSesame";
password[0] = toupper(password[0]);
for (int i = 1; i < password.size(); ++i) {
password[i] = tolower(password[i]);
}
password.push_back('!');
cout<<password;
return 0;
}
QUESTION 9 ) b
// Screenshot of the code

// Sample output

// code to copy
#include <iostream>
using namespace std;
int main() {
string address = "123 Main St., Somewhere, CA
93299";
string street = "";
int index1 = address.find('.');
int index2 = address.find(',');
if (index1 > -1 && index2 > -1) {
if (index1 < index2) {
street = address.substr(0, index1);
}
else {
street = address.substr(0, index2);
}
}
cout<<street;
return 0;
}
QUESTION 10 ) d
Explanation:
explicitly cast the data to indicate that you intend to perform the conversion
QUESTION 1 Given two double variables named x and y, which of the following statements could...
CHAPTER 6 QUESTION 1 Which of these names follows the naming conventions for constants presented in this chapter? a. WeeksInYear b. Weeks_In_Year c. weeks_in_year d. WEEKS_IN_YEAR 1 points QUESTION 2 Which of the following data types can you not use to store the value 500? a. float b. char c. int d. double 1 points QUESTION 3 What values are in the vector named pressures after the following code is executed? vector pressures; pressures.push_back(32.4); pressures.push_back(33.5); pressures.insert(pressures.begin(), 34.2); int index =...
This is my code in C++, my code is working pretty good but there are some stuff needs ti be changed I included theb below the my code: include<iostream> #include<string> #include<vector> #include<sstream> #include<algorithm> using namespace std; //Structure struct TokenFreq { //Structure variables string token; int freq=1; }; //Method matrixInit() void matrixInit(vector<vector<int> > &matrix, int numRows, int numCols) { //Declare the needed variables int index1, index2; //Resize matrix.resize(numRows, vector<int>(numCols)); //Loop for(index1 = 0; index1 < numRows; index1++) { //Loop...
Question 1 The following function header represents which programming language? double calc_weekly_pay( double hours_worked, double pay_rate) Question 1 options: Python A C-based language FORTRAN COBOL Question 2 One of my favorite quotes from Jeanette Wind is "Computational thinking is using abstraction and decomposition when attacking a large complex task or designing a large complex system." This supports using _____________ when developing programs. Question 2 options: Repetition structures Assignment statements Selection structures Functions Question 3 The following assignment statement exhibits which...
Question 1 What is the value of x after the following int x = 5; x++; x++; x+=x++; A)14 B)10 C)13 D)15 Question 2 The last line in value returning function (before the }) should contain the word return. True False Question 3 This contains three parts: Void or Data Type the name optional parameter list A)Menu System B)Function Header C)Switch Question 4 What is a variable? A)a pointer B)a place in memory to hold data C)int D)a computer programming...
1) Given the following “BasicAccount” class #include <iostream> #include <string> class BasicAccount { private: std::string m_username ; std::string m_password ; public: BasicAccount(std::string username, std::string password) { m_username = username ; m_password = password ; } virtual std::string toString() { return "USERNAME(" + m_username + ") PASSWORD(" + m_password + ")" ; } std::string getUserName() { return m_username ; } virtual...
1- Create the base class Book that has the following instance variables, constructor, and methods title ( String) isbn ( String) authors (String) publisher (String) edition ( int) published_year (int) Constructor that takes all of the above variables as input parameters. set/get methods ToString method // that return sting representation of Book object. 2- Create the sub class New_Book that is derived from the base class Book and has the following instance variables, constructor, and methods: title ( String) isbn...
Given the following code segment, int x = 20; int y = 7; what is the data type of the value of the expression (x % y) ? (3 points) Question 1 options: 1) int 2) double 3) numeric 4) Error: possible loss of precision 5) Unable to be determined Question 2 (3 points) Given the following code segment, double x = 42.3; double y = 11.7; what is the data type of the value of the expression (x %...
QUESTION 1 What will be displayed as a result of executing the following code? int x = 5, y = 20; x += 32; y /= 4; cout <<"x = " << x <<"y = " << y; A. x = 32, y = 4 B. x = 9, y = 52 C. x = 37, y = 5 D. x = 160, y = 80 8 points QUESTION 2 What will be the displayed when the following code...
C# programming
50 pts Question 2:2 1- Create the base class Book that has the following instance variables, constructor, and methods title (String) isbn (String) authors (String) publisher (String) edition ( int) published year (int) Constructor that takes all of the above variables as input parameters. set/get methods ToString method// that return sting representation of Book object. 2-Create the sub class New_Book that is derived from the base class Book and has the following instance variables, constructor, and methods: title...
QUESTION 1 Which of the following Python variable names has syntax error ? OA. A. CSC121 OB. B. CSC121 Oc. C. CSC-121 D. None of the above QUESTION 2 What data type will Python use to store the value of num_students ? num_students = 17.0 A. floating point number (i.e. float) OB. B. integer (i.e. int) Oc. string (i.e. str) Od. D. None of the above