Concept explainers
Explanation of Solution
a.
Th...
Explanation of Solution
b.
Th...
Explanation of Solution
c.
T...
Explanation of Solution
d.
Th...
Explanation of Solution
e.
The default constructor (without parameters) is used to initialize the object fruit1...
Explanation of Solution
f.
The code where each data member can be set individually is shown below. Set functions are used to accomplish the same and these are public functions:
void setName(string);
void setCalories(int);
void setFat(double);
void setSugar(int);
void setCarbohydrate(double);
void setPotassium(double);
The full class definition with the above methods in the public section is shown below:
class foodType
{
public:
void set(string, int, double, int, double, double);
void print() const;
string getName() const;
int getCalories() const;
double getFat() const;
int getSugar() const;
double getCarbohydrate () con...
Explanation of Solution
g.
The statement that would replace the definition of the constructors with a constructor with default parameter is as follows:
foodType(string = "banana", int = 90, double = 0...
Trending nowThis is a popular solution!
Chapter 10 Solutions
C++ Programming: From Problem Analysis to Program Design
- What is outpout? public class Vehicle { public void drive(){ System.out.println("Driving vehicle"); } public class Plane extends Vehicle { @Override public void drive(){ System.out.println("Flying plane"); } public static void main(String args[]) { Vehicle myVehicle myVehicle.drive(); } } = new Plane(); syntax error Driving vehicle Flying plane Flying plane O Driving vehiclearrow_forwardclass Point { private: int x, y ; public: : x(u), y(v) {} Point (int u, int v) int getX) { return x; } int getY () { return y; } void doubleVal() { *= 2: y *= 2; } }; int main () { const Point myPoint (5, 3) myPoint.doubleVal() ; cout << myPoint.getX() << " " return 0; << myPoint.getY() << "\n"; }arrow_forwardpackage pkl public class Parent{ private String name; int id; public double fees private void assignName (String n) { Parent pr1=Parent(); this.name=n;} void assignld (int aid) { this.id=aid;} public void calcFees() { this.fees *=10;} }// Class package pkl public class FollowUP { public void methodUP () { Select one: Check the code above and answer the following: pr1.name="M"; is accessible a. False O b. True } }//Class package pk2 public class TrackMe { public void methodMe () { Parent pr2 Parent(); - } }// Classarrow_forward
- 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_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_forwardFor the following four classes, choose the correct relationship between each pair. public class Room ( private String m type; private double m area; // "Bedroom", "Dining room", etc. // in square feet public Room (String type, double area) m type type; m area = area; public class Person { private String m name; private int m age; public Person (String name, int age) m name = name; m age = age; public class LivingSSpace ( private String m address; private Room[] m rooms; private Person[] m occupants; private int m countRooms; private int m countoccupants; public LivingSpace (String address, int numRooms, int numoccupants) m address = address; new int [numRooms]; = new int [numOceupants]; m rooms %3D D occupants m countRooms = m countOccupants = 0; public void addRoom (String type, double area)arrow_forward
- #pyhton programing topic: Introduction to Method and Designing class Method overloading & Constructor overloading ------------------ please find the attached imagearrow_forwardQ:-Write a statement in ClassA to check out the accessibility of your variable. package package_02; public class ClassB { public int x = 1; int y = 2; private int z =3; } package package_01; import package_02.ClassB; public class ClassA { public static void main(String[] args) { ClassB cb = new ClassB(); // System.out.print(cb.x); /* 1 */ // System.out.print(cb.y); /* 2 */ // System.out.print(cb.z); /* 3 */ } }arrow_forward2arrow_forward
- Consider the following class definition: class circle { public: void print() const; void setRadius(double); void setCenter(double, double); void getCenter(double&, double&); double getRadius(); double area(); circle(); circle(double, double, double); double, double); private: double xCoordinate; double yCoordinate; double radius; } class cylinder: public circle { public: void print() const; void setHeight(double); double getHeight(); double volume(); double area(); cylinder(); cylinder(double, double, private: double height; } Suppose that you have the declaration: cylinder newCylinder; Write the definitions of the member functions of the classes circle and cylinder. Identify the member functions of the class cylinder that overrides the member functions of the class circlearrow_forwardGiven the following class definition: class employee{public: employee(); employee(string, int, double); employee(int, double); employee(string); void setData(string, int, double); void print() const; void updatePay(double); int getNumOfServiceYears() const; double getPay() const;private: string name; int numOfServiceYears; double pay;}; Create a class parttime derived from the above class that includes private members payRate and hoursWorked of type double along with a constructor and the definition of a print function that prints out all information from the base and derived class. Provide a test program that would demonstrate the working parttime class. Note: You can assume all code is stored in a single file.arrow_forwardConsider the following class definition: (8)class base{public:void setXYZ(int a, int b, int c);void setX(int a);int getX() const { return x; }void setY(int b);int getY() const { return y; }int mystryNum() { return (x * y - z * z); }void print() const;base() {}base(int a, int b, int c);protected:void setZ(int c) { z = c; }void secret();int z = 0;private:int x = 0;int y = 0;};a. Which member functions of the class base are protected?b. Which member functions of the class base are inline?c. Write the statements that derive the class myClass from classbase as a public inheritance.d. Determine which members of class base are private, protected,and public in class myClass.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