Question

In: Computer Science

Consider the following statements: #include #include class Temporary { private: string description; double first; double second;...

Consider the following statements: #include #include class Temporary { private: string description; double first; double second; public: Temporary(string = "", double = 0.0, double = 0.0); void set(string, double, double); double manipulate(); void get(string&, double&, double&); void setDescription(string); void setFirst(double); void setSecond(double); }; Write the definition of the member function set() so that the instance variables are set according to the parameters. Write the definition of the constructor so that it initializes the instance variables using the function set() Write the definition of the member function manipulate() that returns a decimal number (double) as follows: If the value of description is "rectangle", it returns first * second If the value of description is "circle" it returns the area of a circle with radius first if the value of description is "cylinder" it returns the volume of a cylinder with radius first and height second. HINT: the volume of a cylinder is simply the area of the circle at the base times the height. If the value of description is "sphere" it returns the volume of the sphere with radius first. Otherwise it returns -1.0; To save you googling what the formula for the volume of a sphere is, given the radius of the sphere, it is V=43πr3 HINT: was included for a reason for the manipulate() function.

Solutions

Expert Solution

CODE

#include <iostream>

#define PI 3.14159

using namespace std;

class Temporary {

private:

string description;

double first;

double second;

public:

Temporary(string = "", double = 0.0, double = 0.0);

void set(string, double, double);

double manipulate();

void get(string&, double&, double&);

void setDescription(string);

void setFirst(double);

void setSecond(double);

};

void Temporary::set(string desc, double f, double s) {

description = desc;

first = f;

second = s;

}

void Temporary::setDescription(string desc) {

description = desc;

}

void Temporary::setFirst(double f) {

first = f;

}

void Temporary::setSecond(double s) {

second = s;

}

Temporary::Temporary(string desc, double f, double s) {

set(desc, f, s);

}

void Temporary::get(string& desc, double& f, double& s) {

desc = description;

f = first;

s = second;

}

double Temporary::manipulate() {

if (description == "rectangle") {

return first * second;

} else if (description == "circle") {

return PI * first * first;

} else if (description == "cylinder") {

return 2 * PI * first * (first + second);

} else if (description == "sphere") {

return 4.0/3.0 * PI * first * first * first;

}

return -1;

}


Related Solutions

Consider the following class: import java.util.Scanner; public class MyPoint { private double x; private double y;...
Consider the following class: import java.util.Scanner; public class MyPoint { private double x; private double y; public MyPoint() { this(0, 0); } public MyPoint(double x, double y) { this.x = x; this.y = y; } // Returns the distance between this MyPoint and other public double distance(MyPoint other) { return Math.sqrt(Math.pow(other.x - x, 2) + Math.pow(other.y - y, 2)); } // Determines if this MyPoint is equivalent to another MyPoint public boolean equals(MyPoint other) { return this.x == other.x &&...
Consider the following class: import java.util.Scanner; public class MyPoint { private double x; private double y;...
Consider the following class: import java.util.Scanner; public class MyPoint { private double x; private double y; public MyPoint() { this(0, 0); } public MyPoint(double x, double y) { this.x = x; this.y = y; } // Returns the distance between this MyPoint and other public double distance(MyPoint other) { return Math.sqrt(Math.pow(other.x - x, 2) + Math.pow(other.y - y, 2)); } // Determines if this MyPoint is equivalent to another MyPoint public boolean equals(MyPoint other) { return this.x == other.x &&...
In Java, Here is a basic Name class. class Name { private String first; private String...
In Java, Here is a basic Name class. class Name { private String first; private String last; public Name(String first, String last) { this.first = first; this.last = last; } public boolean equals(Name other) { return this.first.equals(other.first) && this.last.equals(other.last); } } Assume we have a program (in another file) that uses this class. As part of the program, we need to write a method with the following header: public static boolean exists(Name[] names, int numNames, Name name) The goal of...
import java.util.Scanner; public class CompareNums { private static String comparison( int first, int second){ if (first...
import java.util.Scanner; public class CompareNums { private static String comparison( int first, int second){ if (first < second) return "less than"; else if (first == second) return "equal to"; else return "greater than";       }    // DO NOT MODIFY main! public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter first integer: "); int first = input.nextInt(); System.out.print("Enter second integer: "); int second = input.nextInt(); System.out.println("The first integer is " + comparison(first, second) + " the...
java code ============ public class BankAccount { private String accountID; private double balance; /** Constructs a...
java code ============ public class BankAccount { private String accountID; private double balance; /** Constructs a bank account with a zero balance @param accountID - ID of the Account */ public BankAccount(String accountID) { balance = 0; this.accountID = accountID; } /** Constructs a bank account with a given balance @param initialBalance the initial balance @param accountID - ID of the Account */ public BankAccount(double initialBalance, String accountID) { this.accountID = accountID; balance = initialBalance; } /** * Returns the...
java programing Q: Given the following class: public class Student { private String firstName; private String...
java programing Q: Given the following class: public class Student { private String firstName; private String lastName; private int age; private University university; public Student(String firstName, String lastName, int age, University university) { this.firstName = fisrtName; this.lastName = lastName; this.age = age; this.university = university; } public String getFirstName(){ return firstName; } public String getLastName(){ return lastName; } public int getAge(){ return age; } public University getUniversity(){ return university; } public String toString() { return "\nFirst name:" + firstName +...
Java programming. ** Create Account class include: 1/ private long   accountNumber; 2/ private String firstName; 3/...
Java programming. ** Create Account class include: 1/ private long   accountNumber; 2/ private String firstName; 3/ private String lastName; 4/ private double balance; 5/ public Account(long accountNumber, String firstName, String lastName, double balance); 6/ get/set methods for all attributes. 7/ public boolean deposit(double amount);   • deposit only if amount is greater than 10 but   less than 200, add the deposit   amount   to the   currentbalance. • if deposit is   successful return true,   otherwise return false; 8/ public boolean withdrawal(double amount); •...
public class StringNode { private String item; private StringNode next; } public class StringLL { private...
public class StringNode { private String item; private StringNode next; } public class StringLL { private StringNode head; private int size; public StringLL(){ head = null; size = 0; } public void add(String s){ add(size,s); } public boolean add(int index, String s){ ... } public String remove(int index){ ... } } In the above code add(int index, String s) creates a StringNode and adds it to the linked list at position index, and remove(int index) removes the StringNode at position...
COMPLETE JAVA CODE public class Point2 { private double x; private double y;    /** *...
COMPLETE JAVA CODE public class Point2 { private double x; private double y;    /** * Create a point with coordinates <code>(0, 0)</code>. */ public Point2() { complete JAVA code this.set(0.0, 0.0); COMPLETE CODE }    /** * Create a point with coordinates <code>(newX, newY)</code>. * * @param newX the x-coordinate of the point * @param newY the y-coordinate of the point */ public Point2(double newX, double newY) { complete Java code this.set(newX, newY); }    /** * Create a...
package mac286.LinkedLists; public class Postfix { private rStack<String> S; private String inSt; private ourLinkedList<String> inList, outList;...
package mac286.LinkedLists; public class Postfix { private rStack<String> S; private String inSt; private ourLinkedList<String> inList, outList; public Postfix(String s) { S = new rStack<String>(); inSt = s; outList = new ourLinkedList<String>(); inList = new ourLinkedList<String>(); } public void reset(String s) { S = new rStack<String>(); inSt = s; outList = new ourLinkedList<String>(); inList = new ourLinkedList<String>(); } private boolean isOperator(char c) { if(c=='-'||c=='+'||c=='*'||c=='/') return true; return false; } private boolean isParenthesis(char c) { if(c == '(' || c==')') return true;...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT