Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The Calculator and The Quiz In this assignment you need to write and execute a program that will read a single character input from the

The Calculator and The Quiz

In this assignment you need to write and execute a program that will read a single character input from the user and will depending on that input (A or Q) either do a calculation or run a quiz. For each of those you must read additional input:

Calculator:

For this part, after the user types in A, you must inform the user that he is running a calculator and then prompt for two numbers. Store these numbers as floating point values for accuracy. Then you will prompt the user for a single character that will indicate what mathematical operation he wishes to do:

A: Addition (add the two numbers together)

S: Subtraction

M: Multiplication

D: Division (divide them and make sure you use floats to ensure accuracy)

P: Power (for this one you will take the first number as your base and the second as the exponent.) C: Comparison (for this one you will compare the two numbers and say whether the first one is greater than/less than/equal to second.)

O: Modulus (for this one you will have to cast both values to integers first, then do modulus. Make sure you use the letter O as in Owl, not the number zero.)

If the user types any other character than above you will do the inverse operation on the first number (So 2 becomes -2 or -4 becomes 4).

Furthermore, you must error check for the division operation if the second number is equal to zero and if it is give out an error message Division by Zero Detected. Aborting! and then abort the program by adding the statement return -1; directly after it.

Do the same in the case that you are using the Power function and the first number is equal to zero and the second number is less than 0.

Quiz (made by Discord User *** (one of my old 302 students)):

You are starting a weeb/anime club and want to develop an admission exam. You will ask them a series of questions and will create an ongoing score for each question. If their answer is not in the ways of the weeb you will subtract 5 points from their score. If their answer is great example of what an anime connoisseur should be then you will add 5 points. Starting with a score of 0, if at the end of the test their score is positive then they will be approved for the club, but if their score is 0 or negative they will be banned from the sacred grounds of the club. Because each question is a Yes or No question, if the user gives anything other than a Y or N as a response to a question, then score that question with a 0 (dont change their score either way).

The following are the questions you must ask along with how to score them:

Q: Do you agree that Japanese animation are nothing more than cartoons

A: Y -5 , N +5 (this means give Yes answer a -5 in their score and a No answer a +5 in their score.

Q: Can you tell when people are speaking Japanese?

A: Y+5, N-5

Q: Do you hate body pillows?

A: Y-5, N+5

Q: Have you seen the toothbrush scene?

A: Y+5, N-5

Q: Did you ever hear the tragedy of Darth Plagueis The Wise?

A: Y-0, N+0 (does not matter what they answer)

After this question you must output the following text:

I thought not. It's not a story the Jedi would tell you. It\\'s a Sith legend. Darth Plagueis was a Dark Lord of the Sith, so powerful and so wise he could use the Force to influence the midichlorians to create life... He had such a knowledge of the dark side that he could even keep the ones he cared about from dying. The dark side of the Force is a pathway to many abilities some consider to be unnatural. He became so powerful... the only thing he was afraid of was losing his power, which eventually, of course, he did. Unfortunately, he taught his apprentice everything he knew, then his apprentice killed him in his sleep. It's ironic he could save others from death, but not himself.

Q: Is it possible to learn this power?

A: Y-0, N+0 (does not matter what they answer)

Q: Do you own anything imported from Japan excluding Cameras and watches? A: Y+5, N-5

Q: Do you use or watch bleach ? Answer U for use, W for watch)

A: U do -5, W do +5 to the running score

After the last question compute the score and print whether the user is accepted or rejected to the Weeb Club. See sample output. In the special case that they achieved the highest possible positive score, along with acceptance offer them the role of club president.

After completing this assignment you will be able to:

-Make use of C++ input/output commands

-Demonstrate skill in arithmetic operations

-Ability to typecast

-Mastery of the if, if/else, and if/else/if statements

-Mastery in the Jedi Arts, but we do not grant you the rank of master.

Notes:

-Comment your source code appropriately.

-Make sure you name your program file in accordance with the syllabus stipulations -Test your program by running it a few times with different values to make sure the output is correct for all cases My sample outputs are not enough to fully test your program. Come up with your own! -Make sure your output is EXACTLY formatted like the samples or you will lose points. This includes spacing, line feeds, and even upper/lower casing of words.

-The quiz has 3 outcomes. Make sure you have them all AYAYAYA!

Sample Input:

A

5.99

2.1

O

Sample output: (bold is what user typed in) $ g++ assignment.cpp

$ ./a.out

Enter Which Program You Wish To Run: A: Calculator

Q: Quiz

A

Running Calculator

Enter First Number: 5.99

Enter Second Number: 2.1

Enter operation to perform from list: A: Addition

S: Subtraction

M: Multiplication

D: Division

P: Power

C: Comparison

O: Modulus

O

The Answer to life is: 1

$

Another Example:

$ g++ assignment.cpp

$ ./a.out

Enter Which Program You Wish To Run: A: Calculator

Q: Quiz

A

Running Calculator

Enter First Number: 4

Enter Second Number: 9

Enter operation to perform from list: A: Addition

S: Subtraction

M: Multiplication

D: Division

P: Power

C: Comparison

O: Modulus

C

4 is less than 9

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions

Question

Prove that if Σ an is absolutely convergent, then a. an

Answered: 1 week ago

Question

Gather internal and external data and prepare financial statements.

Answered: 1 week ago