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

What is wrong with the following program? #include namespace mySpace { const dou

ID: 3763921 • Letter: W

Question

What is wrong with the following program? #include namespace mySpace { const double RATE = 15.35; int a; using namespace std; int main() { int b; cin b; a = b; cout RATE a + 2 b endl; return 0; } Consider the following statement: string str = "Now is the time for the party!"; What is the output of the following statements? (Assume that all parts are independent of each other.) cout str.size () endl; cout str. substr (7, 8) endl; string: :size_type ind = str.find('f'); string s = str.substr(ind + 4, 9); cout s endl; cout str .insert (11, "best ") endl; str .erase (16, 14); str.insert(16, "to study for the exam?"); cout str endl; Define a struct, carType, to store the following data about a car: Manufacturer (string), model (string), model type (string), color (string), number of doors (int), miles per gallon in city (int), miles per gallon on highway (int), year when the car was built (int), and the price (double).

Explanation / Answer

1. When you are including the namespace std. And when calling variables a, and RATE which belong to other namespace mySpace, you should call those variables along with their namespace like mySpace::RATE, and mySpace::a. These variables has been called 3 times, in your main() which will lead to errors. So, replace the variable calls at lines 12, and 13(here you called the variables twice.). along with their namespace.

2.

a. Displays the size of the string. i.e., 30 will be printed to the screen.

b. The substring from index 7, will be displayed, 8 characters from there. i.e., the time will be printed to the screen.

c. Line 1 will find the index of the first appearance of the character 'f' in the string. i.e., 16.

Line 2 will copy the substring from ind(16) + 4, a total of 9 characters to str. i.e., the party is assigned to str.

Line 3 s will be printed to the screen. i.e., the party

d. The string best will be inserted into the string at position 11, and the string will be printed. i.e., it will print:

  Now is the best time for the party!

e. Forgetting the step d. the string from index 16, a total of 14 characters will be removed from the original string, and starting from index 16 the string "to study for the exam?" will be inserted and printed. i.e., it will print:

  Now is the time to study for the exam?

2. Here is the code for you:

struct carType
{
string manufacturer;
string model;
string modelType;
string color;
int numberOfDoors;
int milesPerGallonInCity;
int milesPerGallonOnHighway;
int yearOfCarBuilt;
double price;
};

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote