Question

Part 4: Creating a Torus Class 8A5bcwSgAAAAlwSFlzAAAOwwAADsMBx2+oZAAAAA

Write a code in C++ that does the following

Add comments// for understanding please

Specifications:

A. Write a class declaration named Torus to find the surface area and volume of a torus.

B. Define appropriate member variables.

C. Define appropriate set (mutator) and get (accessor) functions.

D. Use appropriate code to ask the user for input.

E. Use appropriate member functions to “set” and store the input.

F. Use appropriate member functions to “get” and display the output.

C:\Qt\Tools QtCreator bin\qtcr Enter R (BIG R): -4 Enter r (small r): 3 Invalid value for bigR! C:\Qt\Tools QtCreator bin\qtc

0 0
Add a comment Improve this question Transcribed image text
Answer #1

C++ Code:

#include <iostream>

using namespace std;

class Torus{

private:

int BigR,SmallR;

public:

void setRadius(int BgR,int SmR) {

BigR=BgR;

SmallR=SmR;

}

void get() {

cout<<"Torus Data\n--------------------"<<endl;

double sArea=(2*3.14*BigR)*(2*3.14*SmallR);

double volume=(3.14*SmallR*SmallR)*(2*3.14*BigR);

cout<<"BigR = "<<BigR<<endl;

cout<<"SmallR = "<<SmallR<<endl;

cout<<"Surface Area = "<<sArea<<"sq Units"<<endl;

cout<<"Volume = "<<volume<<" cubic Units";

}

};

int main() {

Torus tor;

int sRadius;

int bRadius;

cout<<"Enter R(Big Radius): ";

cin>>bRadius;

cout<<"Enter r(Small Radius): ";

cin>>sRadius;

if(sRadius<0){

cout<<"Invalid Value for smallR!";

}

else if(bRadius<0)

cout<<"Invalid Value for bigR!";

else{

tor.setRadius(bRadius,sRadius);

tor.get();

}

return 0;

}

clang version 7.0.0-3-ubuntu0.18.04.1 (tags/RELEASE_700/final) ? clang++-7 pthread -o main main.cpp } ./main Enter R (Big Rad

clang version 7.0.0-3-ubuntu0.18.04.1 (tags/RELEASE_700/final) } clang++-7 pthread -o main main.cpp } ./main Enter R (Big Rad

clang version 7.0.0-3-ubuntu0.18.04.1 (tags/RELEASE_700/firal) ? clang++-7 pthread -o main main.cpp } ./main Enter R (Big Rad

if you like the answer please provide a thumbs up.

Add a comment
Know the answer?
Add Answer to:
Part 4: Creating a Torus Class Write a code in C++ that does the following Add...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 1. A torus has 2 parameters r and r that are related to the equation a) Based on the above equation, what is a and b for the torus? b) Use double integral to get the volume of this torus c) Use d...

    1. A torus has 2 parameters r and r that are related to the equation a) Based on the above equation, what is a and b for the torus? b) Use double integral to get the volume of this torus c) Use double integral to get the surface area of this torus. 1. A torus has 2 parameters r and r that are related to the equation a) Based on the above equation, what is a and b for the...

  • 1. A torus has 2 parameters r and r that are related to the equation a) Based on the above equation, what is a and b for the torus? b) Use double integral to get the volume of this torus. c) Use...

    1. A torus has 2 parameters r and r that are related to the equation a) Based on the above equation, what is a and b for the torus? b) Use double integral to get the volume of this torus. c) Use double integral to get the surface area of this torus. d) Let's say you have a circle on the xy-axis with the centre (a, a) and radius b as shown in the figure below, where a > b....

  • C++ Lab 9A Inheritance Employee Class Create a project C2010Lab9a; add a source file Lab9a.cpp to...

    C++ Lab 9A Inheritance Employee Class Create a project C2010Lab9a; add a source file Lab9a.cpp to the project. Copy and paste the code is listed below: Design a class named Employee. The class should keep the following information in member variables: Employee name Employee number Hire date // Specification file for the Employee class #ifndef EMPLOYEE_H #define EMPLOYEE_H #include <string> using namespace std; class Employee { private:        // Declare the Employee name string variable here. // Declare the Employee...

  • Please help with this assignment. Thanks. 1. Write a C++ program containing a class Invoice and...

    Please help with this assignment. Thanks. 1. Write a C++ program containing a class Invoice and a driver program called invoiceDriver.cpp. The class Invoice is used in a hardware store to represent an invoice for an item sold at the store. An invoice class should include the following: A part number of type string A part description of type string A quantity of the item being purchased of type int A price per item of type int A class constructor...

  • Part I: Problem: Code the following in Java: Candy Class -price -number of pounds sold Create...

    Part I: Problem: Code the following in Java: Candy Class -price -number of pounds sold Create the following methods: -Two constructors – default and second - accessor and mutator methods for each of the fields. - check for invalid price. Negative price is invalid (use if then else and display error message) - a method named userInput to get user input for all the fields. - check for invalid price. Negative price is invalid (use a loop to prompt the...

  • Code the following Program in C++ Define a class named Payment that contains a member variable...

    Code the following Program in C++ Define a class named Payment that contains a member variable of type float that stores the amount of the payment and appropriate accessor and mutator methods.    Also create a member function named paymentDetails that outputs an English sentence that describes the amount of the payment. Next define a class named CashPayment that is derived from Payment. This class should redefine the paymentDetails function to indicate that the payment is in cash. Include appropriate constructor(s)....

  • Question 2) Use Point class to define another class called Rectangle which has only two data memb...

    C++ Question 2) Use Point class to define another class called Rectangle which has only two data members of type Point named UpperLeftPoint and BottomRightPoint a. Define two constructors one is default and one is initializer b. Define member functions named getLength of rectangle c. Define member functions named get Width of rectangle d. Define member functions named getArea of rectangle. Note, the values of the functions are calculated based on the two points of the rectangle e. Define member...

  • Design a class named Employee. The class should keep the following information in

    WRITE IN C++ ONLY PLEASE. IM USING VISUAL STUDIO CODE.1. Employee and ProductionWorker ClassesDesign a class named Employee. The class should keep the following information in• Employee name• Employee number• Hire dateWrite one or more constructors and the appropriate accessor and mutator functions for the class.Next, write a class named ProductionWorker that is derived from the Employee class. The ProductionWorker class should have member variables to hold the following information:• Shift (an integer)• Hourly pay rate (a double )The workday...

  • Exercise 1: Create a class Resource. The class should have: a) Two private variables status and w...

    C++C++ Exercise 1: Create a class Resource. The class should have: a) Two private variables status and writeTo representing integer value either 0 or 1. b) One default constructor that initializes the status and writeTo to zero. c) One single parameterized constructor to initialize the writeTo variable. d) Two constant accessor functions per class that return the values of status e) Two mutator functions per class that set the values of status and writeTo One output (member) function that outputs...

  • Design a class for python named PersonData with the following member variables: lastName firstName address city...

    Design a class for python named PersonData with the following member variables: lastName firstName address city state zip phone Write the appropriate accessor and mutator functions for these member variables. Next, design a class named CustomerData , which is derived from the PersonData class. The CustomerData class should have the following member variables: customerNumber mailingList The customerNumber variable will be used to hold a unique integer for each customer. The mailingList variable should be a bool . It will be...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT