Question: 1-6. Write C++ statements that do the following: 1. Define an enumerated type for common colors with values for RED, GREEN, BLUE, YELLOW, ORANGE, and

1-6. Write C++ statements that do the following:

1. Define an enumerated type for common colors with values for RED, GREEN, BLUE, YELLOW, ORANGE, and PURPLE. (By using that order, the color purple will be last.)

2. Declare an enumerated color variable called col.

3. Assign to col the color GREEN.

4. Increment col to the next value. (This only makes sense for variables which are not equal PURPLE.)

5. Create a switch statement to output an uppercase string representing which color col is. (Hint - using Visual Studio will make this easier.)

6. Create a switch statement to assign a color to col based on the character ch when contains the first character of the color in either uppercase are lowercase form. For instance, when variable ch is either 'B' or 'b' assign blue to col. For instance, when variable ch is either 'Y' or 'y' assign yellow to col Etc.

7-9. Consider the following C++ code:

string str1; string str2; char ch; int index; cin >> str1; cin >> str2; cin >> index; ch = str1[index]; str1[index] = str2[index]; str2[index] = ch; cout << str1 << " " << str2;

7. What is the output if the input is Hello here 0?

8. What is the output if the input is Diamond Art 1?

9. What is the output if the input is C++ python 2?

10-12. Suppose that you have the following statements: string str4, str3; cin >> str4 >> str3; if (str3 == str4) cout << str3 + " = " + str4 << endl; else if (str3 > str4) cout << str3 + " > " + str4 << endl; else cout << str3 + " < " + str4 << endl; Answer the following questions:

10. What is the output if the input is card cart?

11. What is the output if the input is cart car?

12. What is the output if the input is Car Car?

13-16. What is the output of the following statements? (Assume that all parts are independent of each other.)

13. string str = "*Happy new years!*"; cout << str.substr(8, 5) << endl;

14. string str = "*Happy new years!*"; string::size_type ind = str.find('y'); string s = str.substr(ind, 4); cout << s << endl;

15. string str = "*Happy new years!*"; cout << str.insert(6, ", new") << endl;

16. string str = "*Happy new years!*"; str.insert(0, "race car");

str.erase(8, 15);

cout << str << endl;

cout << endl;

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Lets go through each part of the question step by step Part 16 Enumerated Types and Switch Statements Define an Enumerated Type for Colors cpp enum Co... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!