need help with c++
Class: Desk
Data members: weight (integer)
Write all external function definition required to make the following code compile:
Desk d1{30}, d2{};
cin >> d2;
if( d1 > d2 )
cout << (++d2) << "\n";
Include a comment for each function indicating if it is a member, non-member, or friend overload for clarity.
#include <iostream>
using namespace std;
class Desk{
public:
int weight;
Desk(int w){
weight=w;
}
Desk(){
}
//overloading gretarer then operator
int operator >(Desk d){
if(weight>d.weight)
return 1;
else
return 0;
}
//overloading preincrement operator
int operator++(){
++weight;
return weight;
}
//overloading >> operator
friend istream &operator>>(istream &in,Desk &d){
in>>d.weight;
return in;
}
};
int main()
{
Desk d1(30),d2;
cin>>d2;
if(d1>d2)
cout<<++d2;
return 0;
}
Step by stepSolved in 2 steps with 1 images
- I don't want static data members or member functions.arrow_forwardNested function classwork 2 Write 'taxIncome', a user-defined function that calculates income tax. y = taxincome (income) defines the principal function. The main function calculates adjusted income as income - 6000. Then y = compute Tax is called. For y = 0.28*Adjusted Income, this function uses 'Adjusted Income'. 'Adjusted Income' was defined in the main function. Use $80,000 income.arrow_forwardSet-up and implementation code for a void function MaxYou are not required to write a complete C++ program but must write and submit just your responses to the four specific function related questions below: QC1: Write the heading for a void function called Max that has three intparameters: num1, num2 and greatest. The first two parameters receive data from the caller, and greatest is used to return a value as a reference parameter. Document the data flow of the parameters with appropriate comments*. QC2: Write the function prototype for the function in QC1. QC3: Write the function definition of the function in QC1 so that it returns the greatest of the two input parameters via greatest, a reference parameter. QC4: Add comments to the function definition* you wrote in QC3 that also states its precondition and postcondition.arrow_forward
- #include <iostream>using namespace std; struct Person{ int weight ; int height;}; int main(){ Person fred; Person* ptr = &fred; fred.weight=190; fred.height=70; return 0;} What is a correct way to subtract 5 from fred's weight using the pointer variable 'ptr'?arrow_forwardall operators that can be overloaded can be implemented as either member functions or regular functions. True Falsearrow_forwardC++ Code Step 1: Preparation For the moment, "comment out" the following under-construction code: In dynamicarray.h: All function prototypes except the constructors and destructor. Keep the member variables (but we will be replacing them shortly). In dynamicarray.cpp: All function implementations except the constructors and destructor. You should also remove (not just comment out) INITIAL_CAP, and replace it with a hard-coded 10 inside the default constructor. This will also eventually go away. In main: Comment out all the code inside the RunPart1Tests function between the linesbool pass = true; and return pass; • Also in main: Comment out all the code in the main function starting with the "Equality comparison" comment and just before the "return 0;" line. Step 2: Replacing member data and the two constructors You're going to replace the current member data (arr, len, and capacity) with a single vector of integers. Remember that vectors keep track of their own size and capacity, so…arrow_forward
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY