Concept explainers
A) class Circle:
{
private
double centerX;
double centerY;
double radius ;
public
setCenter(double, double) ;
setRadius(double };
}
B) Class Moon;
{
Private;
double earthWeight;
double moonWeight;
Public;
moonWeight (double ew);// Constructor
{ earthWeight = ew; moonWeight = earthWeight / 6; }
double getMoonWeight ();
{ return moonWeight; }
}
int main()
{
double earth ;
cout >> "What is your weight?"·
cin << earth;
Moon lunar(earth );
cout << "On the moon you would weigh"
<<lunar.getMoonWeight() << end l ;
return 0;
}
Want to see the full answer?
Check out a sample textbook solutionChapter 7 Solutions
Starting Out With C++: Early Objects (10th Edition)
Additional Engineering Textbook Solutions
C++ How to Program (10th Edition)
Starting Out with Python (3rd Edition)
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
Java: An Introduction to Problem Solving and Programming (7th Edition)
Software Engineering (10th Edition)
Starting Out with Java: Early Objects (6th Edition)
- interface StudentsADT{void admissions();void discharge();void transfers(); }public class Course{String cname;int cno;int credits;public Course(){System.out.println("\nDEFAULT constructor called");}public Course(String c){System.out.println("\noverloaded constructor called");cname=c;}public Course(Course ch){System.out.println("\nCopy constructor called");cname=ch;}void setCourseName(String ch){cname=ch;System.out.println("\n"+cname);}void setSelectionNumber(int cno1){cno=cno1;System.out.println("\n"+cno);}void setNumberOfCredits(int cdit){credits=cdit;System.out.println("\n"+credits);}void setLink(){System.out.println("\nset link");}String getCourseName(){System.out.println("\n"+cname);}int getSelectionNumber(){System.out.println("\n"+cno);}int getNumberOfCredits(){System.out.println("\n"+credits); }void getLink(){System.out.println("\ninside get link");}} public class Students{String sname;int cno;int credits;int maxno;public Students(){System.out.println("\nDEFAULT constructor…arrow_forwardclass Lease{ private String name; private int aptNumber; private double rent; private int term; private static final int FEE = 10; public Lease(){ name = "XXX"; aptNumber = 0; rent = 1000; term = 12; } public void setName(String tenant) { name = tenant; } public void setAptNumber(int apt){ aptNumber = apt; } public void setRent(double monthRent) { rent = monthRent; } public void setTerm(int t){ term = t; } public String getName(){ return name; } public int getAptNumber(){ return aptNumber; } public double getRent(){ return rent; } public int getTerm(){ return term; } public void addPetFee(){ rent = rent + FEE; } } Create a class named TestLease as instructed below: Instantiate four Lease objects in the main()method. Change the aptNumber value for the first object to 20 Change the rent value…arrow_forward49. Consider the following class definition. public class Cylinder } private double baseRadius; private double height; public Cylinder () baseRadius = 0; height = 0; public Cylinder (double 1, double h) } baseRadius - 1; height = h; { public void set (double r, double h) } baseRadius = r; height = h; { public String toString () } return (baseRadius + It n + height); { public double SurfaceArea () return 2 * 3.14 * baseRadius height; public double volume () } return 3.14 baseRadius * baseRadius * height; { Which of the following statements correctly instantiates the Cylinder object myCylinder? (i) Cylinder mycylinder = new Cylinder (2.5, 7.3) : (ii) class Cylinder myCylinder = new Cylinder (2.5, 7.3); (ii) myCylinder new Cylinder (2.5, 7.3); %3D a. Only (i) b. Only (i) c. Only (iüi) d. Both (ii) and (ii)arrow_forward
- package myq2; class Sale { int sellerID, milksale, buttersale; Sale(int sid, int ms, int bs) { sellerID = sid; milksale- ms; buttersale - bs; } elling dairy ifferent days using OOP ers, based on YQ2 int totalsaving(){ return milksale + buttersale; } } ale public class Myq2 { public static void main(String[] args) { Sale s = new Sale(111, 10, 20); System.out.println("Seller ID" + s.sellerID ); System.out.println("Total Saving "+s.totalsaving()); } } 4) Use the parameterized constructor to initialize the member variables of the class. 5) Display the following details of seller using object of Sale class. seller ID, totalsaving Solution to programarrow_forwardPublic classTestMain { public static void main(String [ ] args) { Car myCar1, myCar2; Electric Car myElec1, myElec2; myCar1 = new Car( ); myCar2 = new Car("Ford", 1200, "Green"); myElec1 = new ElectricCar( ); myElec2 = new ElectricCar(15); } }arrow_forwardpublic class FoodItem { private String name; private double fat; private double carbs; private double protein; // TODO: Define default constructor // TODO: Define second constructor with parameters to initialize private fields (name, fat, carbs, protein) public String getName() { return name; } public double getFat() { return fat; } public double getCarbs() { return carbs; } public double getProtein() { return protein; } public double getCalories(double numServings) { // Calorie formula double calories = ((fat * 9) + (carbs * 4) + (protein * 4)) * numServings; return calories; } public void printInfo() { System.out.println("Nutritional information per serving of " + name + ":"); System.out.printf(" Fat: %.2f g\n", fat); System.out.printf(" Carbohydrates: %.2f g\n", carbs); System.out.printf(" Protein: %.2f g\n", protein); }} import java.util.Scanner; public class NutritionalInfo {…arrow_forward
- public class Plant { protected String plantName; protected String plantCost; public void setPlantName(String userPlantName) { plantName = userPlantName; } public String getPlantName() { return plantName; } public void setPlantCost(String userPlantCost) { plantCost = userPlantCost; } public String getPlantCost() { return plantCost; } public void printInfo() { System.out.println(" Plant name: " + plantName); System.out.println(" Cost: " + plantCost); }} public class Flower extends Plant { private boolean isAnnual; private String colorOfFlowers; public void setPlantType(boolean userIsAnnual) { isAnnual = userIsAnnual; } public boolean getPlantType(){ return isAnnual; } public void setColorOfFlowers(String userColorOfFlowers) { colorOfFlowers = userColorOfFlowers; } public String getColorOfFlowers(){ return colorOfFlowers; } @Override public void printInfo(){…arrow_forwardIncorrect Question 6 public class Shape { Color fillColor; } public Shape() { fill Color = Color. RED; } } public Shape(Color fillColor) { this.fill Color = fillColor; } public class Circle extends Shape { int radius; public Circle() { radius = 1; } public Circle(int radius) { this.radius = radius; } public Circle(int radius, Color fillColor) { } super(fillColor); this.radius = radius; Circle c1= new Circle(); Circle c2= new Circle(5); Circle c3 = new Circle(10, Color.BLUE); Which of the following are correct? c2 has radius 5 c1 is red c2 is red c3 has radius 10 c3 has radius 1 c3 is red c1 is blue ✔c2 has radius 10 c3 is blue c1 has radius 5 c1 has radius 1 c2 has radius 1 c2 is bluearrow_forwardEach of the following class declarations or programs contain errors. Find as many as possible. 73. class Circle: { private double centerX; double centerY; double radius; public setCenter(double, double); setRadius(double); } 74. #include using namespace std; Class Moon; { Private; double earthWeight; double moonWeight; Public; moonWeight(double ew); { earthWeight = ew; moonWeight = earthWeight / 6; } double getMoonWeight(); { return moonWeight; } }arrow_forward
- class Base { public: int x, y: public: Base(int i, int j) { x = i; y = j; }}; class Derived : public Base public: Derived (int i, int j) { x = i; y = j; void display() {cout « x <<" "<< y; }}; int main(void) { Derived d(5, 5); d.display(); return e; Error O X=5,Y=5 X-0,Y=0 None of the above Other:arrow_forwardclass IndexItem { public: virtual int count() = 0; virtual void display()= 0; };class Book : public IndexItem { private: string title; string author; public: Book(string title, string author): title(title), author(author){} virtual int count(){ return 1; } virtual void display(){ /* YOU DO NOT NEED TO IMPLEMENT THIS FUNCTION */ } };class Category: public IndexItem { private: /* fill in the private member variables for the Category class below */ ? int count; public: Category(string name, string code): name(name), code(code){} /* Implement the count function below. Consider the use of the function as depicted in main() */ ? /* Implement the add function which fills the category with contents below. Consider the use of the function as depicted in main() */ ? virtualvoiddisplay(){ /* YOU DO NOT NEED TO IMPLEMENT THIS FUNCTION */ } };arrow_forwardQuestion 1 public class Flat { private int noOfRooms; private double area; private boolean seaView; public Flat() { noOfRooms = 3; area = 200; seaView = true; } %3D public void setFlat(int n, double a, boolean s) { noOfRooms = n; area = a; seaView = s; } public int getNoOfRooms( ) { return noOfRooms; } public double getArea( ) { return area; } public boolean getSeaView( ) { return seaView; } } Write a static method named findFlats that takes as a parameter an array of type Flat named list. The method should count and return the number of flats that have 3 or more rooms and with a sea view. The method prototype is: public static int findFlats (Flat[] list); Note: assume the array is already declared, populated with data in the main method and ready to be used.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education