Please help me with this problem in c++ please no c it must be c++ and main.cpp cannot be modified and the program must

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Please help me with this problem in c++ please no c it must be c++ and main.cpp cannot be modified and the program must

Post by answerhappygod »

Please help me with this problem in c++ please no c it mustbe c++ and main.cpp cannot be modified and the program must havethe 3 files and get the result in the sample
please do not respond with a bunch of instruction that is notwhat I'm looking for since I have tried multiple times and I'm notexperienced enough I'm looking for help in a coding way.
please use visual studio and have a screenshot that shows theprogram working and please be careful of memoryleaks.
Please Help Me With This Problem In C Please No C It Must Be C And Main Cpp Cannot Be Modified And The Program Must 1
Please Help Me With This Problem In C Please No C It Must Be C And Main Cpp Cannot Be Modified And The Program Must 1 (74.4 KiB) Viewed 17 times
main.cpp:
#include<iostream>#include<cstring>#include"Basket.h"#include"Basket.h" //intentional
using namespace std;using namespace sdds;
void printHeader(const char* title){ char oldFill = cout.fill('-'); cout.width(40); cout << "" << endl;
cout << "|> " << title<< endl;
cout.fill('-'); cout.width(40); cout << "" << endl; cout.fill(oldFill);}
int main(){ sdds::Fruit fruits[]{ {"apple", 0.65}, {"banana",1.25}, {"pear", 0.50}, {"mango", 0.75}, {"plum", 2.00}, };
{ printHeader("T1:Default Constructor");
BasketaBasket; cout <<aBasket;
// conversion tobool operator if (aBasket) cout<< "Test failed: the basket should be empty!\n"; else cout<< "Test succeeded: operator said the basket isempty!\n";
cout <<endl; }
{ printHeader("T2:Custom Constructor");
BasketaBasket(fruits, 2, 6.99); cout <<aBasket;
// conversion tobool operator if (aBasket) cout<< "Test succeeded: operator said the basket hascontent!\n"; else cout<< "Test failed: the basket should NOT be empty!\n";
cout <<endl; }
{ printHeader("T3: +=operator");
BasketaBasket; aBasket +=fruits[2]; (aBasket +=fruits[0]) += fruits[4]; aBasket.setPrice(12.234);
cout <<aBasket; cout <<endl; } { printHeader("T4:Copy Constructor");
Basket b1; Basket b2(b1);
cout <<"Basket #1 -> " << b1; cout <<"Basket #2 -> " << b2;
b1 +=fruits[3]; b1.setPrice(3.50);
Basketb3(b1); cout <<"Basket #3 -> " << b3; cout <<endl; }
{ printHeader("T5:Copy Assignment");
Basket b1, b2,b3(fruits, 5, 19.95);
b1 = b2; cout <<"Basket #1 -> " << b1; cout <<"Basket #2 -> " << b2;
b1 = b3; cout <<"Basket #1 -> " << b1;
b3 = b2; cout <<"Basket #3 -> " << b3; }
return 0;}Execution Sample:----------------------------------------|> T1: Default Constructor----------------------------------------The basket is empty!Test succeeded: operator said the basket is empty!
----------------------------------------|> T2: Custom Constructor----------------------------------------Basket Content: apple: 0.65kg banana: 1.25kgPrice: 6.99Test succeeded: operator said the basket has content!
----------------------------------------|> T3: += operator----------------------------------------Basket Content: pear: 0.50kg apple: 0.65kg plum: 2.00kgPrice: 12.23
----------------------------------------|> T4: Copy Constructor----------------------------------------Basket #1 -> The basket is empty!Basket #2 -> The basket is empty!Basket #3 -> Basket Content: mango: 0.75kgPrice: 3.50
----------------------------------------|> T5: Copy Assignment----------------------------------------Basket #1 -> The basket is empty!Basket #2 -> The basket is empty!Basket #1 -> Basket Content: apple: 0.65kg banana: 1.25kg pear: 0.50kg mango: 0.75kg plum: 2.00kgPrice: 19.95Basket #3 -> The basket is empty!
Files needed in the program:
Basket.cppBasket.hmain.cpp
DIY (50%) Basket Module Design and code a class named Basket that holds information about a fruit basket. Place your class definition in a header file named Basket.h and your function definitions in an implementation file named Basket.cpp. Include in your solution all of the statements necessary for your code to compile under a standard C++ compiler and within the sdds namespace. Add to this module a custom type called Fruit : struct Fruit { }; char m_name[ 30 + 1]; // the name of the fruit double m_qty; // quantity in kilograms Basket Class Design and code a class named Basket that holds information about a fruit basket. Basket Private Members The class should be able to store the following data:
m_fruits : a dynamically allocated array of objects of type Fruit. This is the resource that you must manage. m_cnt the size of the m_fruits array. m_price: the price of the basket. You can add any other private members in the class, as required by your design. ● Basket Public Members the default constructor • a custom constructor that receives as parameters an array of objects of type Fruit, the size of the array received in the fist parameter, and the price of the basket (in this order); stores the parameters into the attributes if all the parameters are valid (the numbers are greater than 0, and the array is not null). • the copy constructor (you must do a deep-copy for the resource, and a shallow copy for the other attributes) • the copy assignment operator (you must do a deep-copy for the resource, and a shallow copy for the other attributes; note that the copy constructor and copy assignment operator have almost identical logic -- reuse the code) the destructor void setPrice (double price): updates the m_price attribute to the value received as parameter • the conversion to bool operator: returns true if the basket contains any fruits, false otherwise. • an overload of the + operator that receives as a parameter an object of type Fruit (by value) and adds it to the attribute m_fruits (resize the array-attribute; check previous workshops if you need a refresh on resizing a dynamic array) ● Friend Helper Functions • overload the insertion operator (operator<< ) to insert into the stream (received as the first parameter) the content of an object of type Basket (received as the second parameter). If the basket doesn't contain any fruit, print the message The basket is empty!<ENDL> .
If the basket contains fruits, print the content in the format: Basket Content:<ENDL> [FRUIT_1_NAME]: [FRUIT_1_QUANTITY] kg<ENDL> [FRUIT_2_NAME]: [FRUIT_2_QUANTITY] kg<ENDL> Price: [BASKET_PRICE]<ENDL> The fruit names should be printed on fields of size 10, aligned to the right; the fruit quantities and basket price should be printed with two significant digits.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply