Free. Exclusive. Just for you.
Four unique services that make learning easier, faster, and smarter - only on our website.

Part 2: Programming (15 Pts) This assignment is to | Chegg.com - Free Printable

Part 2: Programming (15 Pts) This assignment is to | Chegg.com

Educational worksheet: Part 2: Programming (15 Pts) This assignment is to | Chegg.com. Download and print for classroom or home learning activities.

JPG 877×1024 248.7 KB Free · Personal Use
Quality Assured by Worksheets Library Team
Reviewed for educational accuracy and age-appropriateness
ID: #1713042
Show Answer Key & Explanations Step-by-step solution for: Part 2: Programming (15 Pts) This assignment is to | Chegg.com
Let’s go step by step to solve this programming task.

We are told to:

1. Define a class called `Quiz` with specific private and public members (as shown in the UML-like diagram).
2. Add dummy implementations for all methods — meaning, just enough code so it compiles and runs without errors, but doesn’t do real logic yet.
3. Update the main function to create a `Quiz` object before a do-loop (though we don’t see the full main, we’ll assume we’re adding that line).

---

Step 1: Class Template



We need to write the class definition exactly as shown, with proper syntax.

Private members:
- `string choiceA, choiceB, choiceC, choiceD, question;`
- `char answer;`
- `string getChoice(char);` ← Wait! This is listed under private, but it’s a method. That might be a typo in the problem. Looking at the public section, `getChoice(char)` is also declared there. So likely, the private list accidentally included it. We should only declare data members in private, and methods in public (or private if intended). But since the problem says “look at the UML” and shows `getChoice(char)` under private, but then again under public — that’s confusing.

Actually, looking carefully: In the image, under private, it lists:

```
string choiceA, choiceB, choiceC, choiceD, question;
char answer;
string getChoice (char);
```

But `getChoice` is a function — it shouldn’t be a data member. And then under public, it’s listed again as a method.

This is probably a mistake in the problem statement. In standard C++, you don’t declare functions as data members like that. The correct interpretation is:

→ Private data members: `choiceA`, `choiceB`, `choiceC`, `choiceD`, `question`, `answer`

→ Public methods: constructor, `displayQuiz()`, `setQuestion()`, `set4Choices()`, `setCorrectAnswer()`, `isCorrect()`, `shuffle()`, and `getChoice(char)`

So I will ignore the erroneous placement of `getChoice(char)` under private and treat it as a public method only.

Also note: `getChoice(char)` returns a string — so it’s meant to return the text of the choice corresponding to the char (e.g., 'A' → choiceA).

---

Step 2: Dummy Methods



We must define each method outside the class (after main? Actually, the problem says: “All methods are defined after the main function.” But typically in C++, we define them after the class, not necessarily after main. However, to follow instructions literally, we’ll put method definitions after main — but that would cause compilation error unless we forward-declare or define inline. Better interpretation: define them after the class, and before or after main — but the problem says “after the main function”. Hmm.

Wait — rereading: “All methods are defined after the main function.” That’s unusual, but possible if we use prototypes inside the class and define bodies later. But in C++, if you define a method body after main, you must have declared the class before main, and the method declarations inside the class act as prototypes.

Actually, no — in C++, you can define member functions anywhere after the class definition, even after main, as long as the compiler has seen the class definition first.

But to keep it simple and follow instructions, we’ll:

- Write the class definition before main.
- Write dummy method definitions after main.

However, the problem says: “update the main function as follows” and adds a line to create a Quiz object. So we need to show a minimal main that includes that line.

Also, the problem says: “submit Assignment5.cpp to Gradescope” — so we’re writing a complete .cpp file.

---

Let’s Build the Code



We’ll write:

1. Include necessary headers (`#include <iostream>`, `#include <string>`)
2. Using namespace std; (for simplicity, as often done in school assignments)
3. Class Quiz definition with all members and method declarations.
4. Main function that creates a Quiz object with dummy values.
5. After main, define all the dummy methods.

Dummy means:
- For void methods: empty body `{ }`
- For non-void methods: return a default value (empty string for string, false for bool, etc.)

Constructor: takes 6 parameters — we’ll assign them to member variables? Or just leave dummy? The problem says “dummy (no error code) statements”, so we can just assign or do nothing. To avoid unused parameter warnings, maybe assign to members? But since it’s dummy, we can skip. However, to make it compile cleanly, let’s assign.

Actually, the problem says: “Keep empty in the void-type method, and make a simple return statement in the return-type method.”

So for constructor — it’s not void, but it doesn’t return anything. In C++, constructors don’t have return type. So we can have an empty body or assign parameters.

To be safe, let’s assign the parameters to member variables in the constructor — that’s what a real constructor would do, and it’s still “dummy” in the sense that other methods aren’t implemented.

But the problem says “dummy methods” — perhaps they mean minimal implementation. Since the constructor is required to take those params, we should store them.

Looking at the example given for `getChoice`:

```cpp
string Quiz::getChoice(char x) {
string out = "";
return out;
}
```

So for consistency, we’ll do similar for others.

For constructor: we can initialize members with the passed values.

But wait — the problem says “dummy (no error code)”, so maybe even simpler: just have empty body for constructor? But then the parameters are unused — might cause warning. Better to assign.

I think assigning is fine and expected.

Let’s proceed.

---

Writing the Code



Here’s the full structure:

```cpp
#include <iostream>
#include <string>
using namespace std;

class Quiz {
private:
string choiceA, choiceB, choiceC, choiceD, question;
char answer;

public:
Quiz(string, string, string, string, string, char);
string displayQuiz();
void setQuestion(string);
void set4Choices(string, string, string, string);
void setCorrectAnswer(char);
bool isCorrect(char);
void shuffle();
string getChoice(char);
};

int main() {
// Add this line before do-loop (we don't have do-loop, but we add the object creation)
Quiz quiz("", "", "", "", "", 'F');

// Rest of main (not specified, so we leave minimal)
return 0;
}

// Now define all methods after main

Quiz::Quiz(string q, string a, string b, string c, string d, char ans) {
question = q;
choiceA = a;
choiceB = b;
choiceC = c;
choiceD = d;
answer = ans;
}

string Quiz::displayQuiz() {
return "";
}

void Quiz::setQuestion(string q) {
}

void Quiz::set4Choices(string a, string b, string c, string d) {
}

void Quiz::setCorrectAnswer(char ans) {
}

bool Quiz::isCorrect(char userAns) {
return false;
}

void Quiz::shuffle() {
}

string Quiz::getChoice(char x) {
string out = "";
return out;
}
```

Wait — the constructor parameters: in the class declaration, it’s:

`Quiz(string, string, string, string, string, char);`

But which is which? The problem doesn’t specify order, but from context, likely:

First string: question

Then four strings: choices A,B,C,D

Last char: answer

In my above, I used:

`Quiz(string q, string a, string b, string c, string d, char ans)`

That matches: q=question, a=choiceA, b=choiceB, c=choiceC, d=choiceD, ans=answer.

Yes.

In the main, we call:

`Quiz quiz("", "", "", "", "", 'F');`

Which passes 5 empty strings and 'F'. So:

- question = ""
- choiceA = ""
- choiceB = ""
- choiceC = ""
- choiceD = ""
- answer = 'F'

Perfect.

Now, check if all methods are defined:

- Constructor: done
- displayQuiz(): returns ""
- setQuestion(): empty
- set4Choices(): empty
- setCorrectAnswer(): empty
- isCorrect(): returns false
- shuffle(): empty
- getChoice(): returns ""

All good.

The problem says: “Don’t go to the next step if your program does not return the proper output in each step.” But since this is Step 2, and we’re doing dummy methods, there’s no expected output — just that it compiles and runs without crashing.

Also, note: the problem mentions “Part 1” and header comment block — but since we don’t have Part 1 details, we’ll omit that for now. The instruction says to finish Part 1 including header comment, but since it’s not provided, we focus on the class and main as described.

For submission, we should include a header comment as per typical assignment requirements. Let’s add a simple one.

Final code with header:

```cpp
// Assignment 5 - Quiz Class Implementation
// Student Name: [Your Name]
// Date: May 20, 2026
// Description: Defines the Quiz class with dummy methods for initial setup.

#include <iostream>
#include <string>
using namespace std;

class Quiz {
private:
string choiceA, choiceB, choiceC, choiceD, question;
char answer;

public:
Quiz(string, string, string, string, string, char);
string displayQuiz();
void setQuestion(string);
void set4Choices(string, string, string, string);
void setCorrectAnswer(char);
bool isCorrect(char);
void shuffle();
string getChoice(char);
};

int main() {
Quiz quiz("", "", "", "", "", 'F');
return 0;
}

Quiz::Quiz(string q, string a, string b, string c, string d, char ans) {
question = q;
choiceA = a;
choiceB = b;
choiceC = c;
choiceD = d;
answer = ans;
}

string Quiz::displayQuiz() {
return "";
}

void Quiz::setQuestion(string q) {
}

void Quiz::set4Choices(string a, string b, string c, string d) {
}

void Quiz::setCorrectAnswer(char ans) {
}

bool Quiz::isCorrect(char userAns) {
return false;
}

void Quiz::shuffle() {
}

string Quiz::getChoice(char x) {
string out = "";
return out;
}
```

This should compile and run without errors.

Note: The problem says “add the template of Quiz class” — we did.

And “update the main function” by adding `Quiz quiz(...)` — we did.

All dummy methods are implemented as specified.

One thing: in the class definition, the private section had `string getChoice(char);` — we removed that because it was likely a mistake. If the grader expects it there, it might cause error. But logically, it’s wrong. Given that in public it’s correctly declared as a method, and in private it’s listed alongside data members, I believe it’s a typo. Our version is correct C++.

If forced to include it in private, we’d have to make it a data member — which doesn’t make sense. So I’ll stick with our version.

Final Answer is the complete code above.

──────────────────────────────────────

Final Answer:
```cpp
// Assignment 5 - Quiz Class Implementation
// Student Name: [Your Name]
// Date: May 20, 2026
// Description: Defines the Quiz class with dummy methods for initial setup.

#include <iostream>
#include <string>
using namespace std;

class Quiz {
private:
string choiceA, choiceB, choiceC, choiceD, question;
char answer;

public:
Quiz(string, string, string, string, string, char);
string displayQuiz();
void setQuestion(string);
void set4Choices(string, string, string, string);
void setCorrectAnswer(char);
bool isCorrect(char);
void shuffle();
string getChoice(char);
};

int main() {
Quiz quiz("", "", "", "", "", 'F');
return 0;
}

Quiz::Quiz(string q, string a, string b, string c, string d, char ans) {
question = q;
choiceA = a;
choiceB = b;
choiceC = c;
choiceD = d;
answer = ans;
}

string Quiz::displayQuiz() {
return "";
}

void Quiz::setQuestion(string q) {
}

void Quiz::set4Choices(string a, string b, string c, string d) {
}

void Quiz::setCorrectAnswer(char ans) {
}

bool Quiz::isCorrect(char userAns) {
return false;
}

void Quiz::shuffle() {
}

string Quiz::getChoice(char x) {
string out = "";
return out;
}
```
Parent Tip: Review the logic above to help your child master the concept of quiz in code worksheet answers.
Print Download

How to use

Click Print to open a print-ready version directly in your browser, or use Download to save the file to your device. The ⭐ Answer button generates an AI answer key instantly - useful for teachers who need a quick reference. Need a different version? Our AI Worksheet Generator lets you create a custom worksheet on any topic in seconds.

(view all quiz in code worksheet answers)

Part 2: Programming (15 Pts) This assignment is to | Chegg.com
Coding Worksheets for Kids | Fun way to learn coding for kids
Famous people QR code quiz - ESL worksheet by tendergirl21
Honor Code Quiz
Quiz &amp; Worksheet - ICD-10-CM Medical Coding | Study.com
Coding Worksheets for Kids | Fun way to learn coding for kids
Coding Worksheets for Kids | Fun way to learn coding for kids
How to build a Quiz Game in Python - DEV Community
C Quiz Questions With Answers | PDF | C (Programming Language ...
Food Chain Code Breaker Worksheet Food Chain Quiz Sheet Food Chain ...