EP MINDTAPV2.0 FOR MALIK'S C++ PROGRAMM
8th Edition
ISBN: 9780357425237
Author: Malik
Publisher: Cengage Learning
expand_more
expand_more
format_list_bulleted
Expert Solution & Answer
Chapter 13, Problem 18SA
Explanation of Solution
The following code shows the error and the corrected statement in the program:
class discover //Line 1
{ //Line 2
friend discover operator+(const discover& a,
const discover& b); //Line 4 - corrected version
//the function must be declared as a friend function
//Returns the object containing the
//sum of the corresponding members
//of the objects a and b...
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
class A
{protected
int x1,y1,z;
public:
A(a, b,c):x1(a+2),y1(b-1),z(c+2) {
for(i=0; i<5;i++)
x1++; y1++;z++;}};
class B
{protected:
int x,y;
public:
B(a,b):x(a+1),y(b+2) {
for(i=0; i<5;i++)
x+=2; y+=1;}};
class D:public B, virtual public A
{ private:
int a,b;
public:
D(k,m,n): a(k+n), B(k,m),b(n+2),A(k,m,n) {
a=a+1;b=b+1;}});
int main()
{D ob(4,2,5);}
what the values of x1,y1 and z
in c++ write aprogram to Create a class Rectangle with length and breadth as private data members and also provide the following member functions:
getdata(): gets the length and breadth of rectangle.
calarea(): return the area of the rectangle.
calperi(): return the perimeter of the rectangle.
issquare(): return true if the rectangle is square
class Airplane – highlights
-- planeID : String
-planeModel: String //”Boeing 757” etc.
--seatCapacity : int //would vary by outfitting
…………
Assume getters and setters, toString(), constructor with parameters
and constructor
………………
Write lambdas using a standard functional interface to:
a) Given a plane object and a required number of seats as an input, determine if the given plane meets or exceeds the required capacity
b) Output the plane description if capacity is less than 80% of a specified number
(We would use his for planning aircraft assigned to various routes. )
c) Adjust the seats in a plane by a specified positive or negative number [after modifications have been made to the interior.]
…and write an example for each showing the usage, using an Airplane instance plane1
Chapter 13 Solutions
EP MINDTAPV2.0 FOR MALIK'S C++ PROGRAMM
Ch. 13 - Prob. 1TFCh. 13 - What are the two things that you need to overload...Ch. 13 - Which of the following operator cannot be...Ch. 13 -
a. Within the definition of an operator function,...Ch. 13 - Prob. 5SACh. 13 -
What is the difference between a friend function...Ch. 13 - Prob. 7SACh. 13 - Prob. 8SACh. 13 -
Suppose that the binary operator + is overloaded...Ch. 13 - Prob. 10SA
Ch. 13 - Prob. 11SACh. 13 -
Suppose that the binary operator + is overloaded...Ch. 13 - Prob. 13SACh. 13 -
Consider the following declaration: (6) class...Ch. 13 - Prob. 15SACh. 13 -
Ch. 13 -
Find the error(s) in the following code: (6)
Ch. 13 - Prob. 18SACh. 13 - Prob. 1PECh. 13 - Redo Programming Exercise 1 by overloading the...
Knowledge Booster
Similar questions
- Data Structuresarrow_forwardclass 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_forwardC++arrow_forward
- Software Requirements: • Latest version of NetBeans IDE • Java Development Kit (JDK) 8 Procedure: 1. our progras from rhFactor non-static and private. Remove the constructor with two (2) parameters. 2o upply uncapsutation Make bloodType and 2. The names of the public setter and getter methods should be: • setBloodType() • setRhFactor() getBlood Type() getRhFactor() 3. Use the setter methods to accept user input. 4. Display the values by calling the getter methods. Sample Output: Enter blood type of patient: Enter the Rhesus factor (+ or -): O+ is added to the blood bank. Enter blood type of patient: B Enter the Rhesus factor (+ or -): B- is added to the blood bank.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_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_forward
- Object oriented programming C++ Use Classes Write a C++ program in which each flight is required to have a date of departure, a time of departure, a date of arrival and a time of arrival. Furthermore, each flight has a unique flight ID and the information whether the flight is direct or not.Create a C++ class to model a flight. (Note: Make separate classes for Date and Time and use composition).add two integer data members to the Flight class, one to store the total number of seats in the flight and the other to store the number of seats that have been reserved. Provide all standard functions in each of the Date, Time and Flight classes (Constructors, set/get methods and display methods etc.).Add a member function delayFlight(int) in the Flight class to delay the flight by the number of minutes pass as input to this function. (For simplicity, assume that delaying a flight will not change the Date). Add a member function reserveSeat(int) which reserves the number of seats passed as…arrow_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_forwardThe following is a definition of class Example:class Example{public:Example( int y = 10 ): data( y ){// empty body} // end Example constructorint getIncrementedData() const{return ++data;} // end function getIncrementedDatastatic int getCount(){cout << "Data is " << data << endl;return count;} // end function getCountprivate:int data;static int count;}; // end class Examplearrow_forward
- Point out errors in the following codes and correct them publicclass CheckingAccount { // Create attributes account Num, Balance privateint accountNum; // Account Number privatedouble balance; // Account balance // Constructor public void CheckingAccount(int aNum, double balance) { // Call setters to initialize attribute values setAccountNumber (aNum); setBalance; } // Setters public void setAccountNumber(int aNum) { if (accountNum >= 100) { accountNum = aNum; } else {System.out.println("This account number is invalid (Account number must be at least 3 digits)!"); this.accountNum = 100; // assign a default value } } public void setBalance(double aBalance) { // make sure the value is positive if (aBalance > 0) { aBalance = balance; } else { System.out.println("This balance value is invalid (input must be positive)!"); aBalance = 0; // assign a default value } } // Getters publicvoid getAccountNumber() { return accountNum; } public void getBalance() { return balance; }…arrow_forward1. Assume the following: class Complex{public:Complex(int, int); //initializes the private data members to the passed in values: // real = value of the first argument // imag = value of the second argumentComplex add( Complex ); //returns a Complex object that holds the sum of two //Complex objectsvoid print(); //prints the values of the private data members in the format: // (real, imag)private:int real, imag;}; Will these two lines work below in a driver program for the class? Complex c1(40,50); //create object (line 1) c1.real=55; //move in value of 55 (line 2) a. yes it will work fine b. no, you will get a compiler error c. need more information on the object d. line 1 will cause an error line 2 will work finearrow_forwardCreate a UML diagram to help design the class baby. class Baby{ //data members private String name; private int age; //default constructor Baby() { name = "xyz"; age = 3; } //parameterized constructor Baby(String n,int a){ name = n; age = a; } //sets name public void setname(String n){ if(n.isEmpty()) name = "xyz"; else name = n; } //sets age public void setage(int a){ if(!(a>=1 && a<=4)) age = 2; else age = a; } //returns name public String getname(){ return name; } //returns age public int getage(){ return age; } //check if two objects have same name and age public boolean equals(Baby b){ if (age==b.getage() && name.equalsIgnoreCase(b.getname())) return true; else return false; } } public class Main { public static void main(String[] args) { //two objects of type Baby Baby A=new Baby("abcd",3); Baby B= new Baby("abcd",3); //print information of object System.out.println("Name:" + A.getname() + " age:"+ A.getage()); //call equals on obejct…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning