#include <iostream>
#include <string>
#include <iomanip>
#include <vector>
usingnamespace std;
class iceCreamTruck
{
private:
staticconst size_t NR_OF_BUYERS=3;
string buyersN[NR_OF_BUYERS];
string dOWeek[NR_OF_BUYERS];
int noIcecream[NR_OF_BUYERS];
public:
void getBuyersDetails()
{
for (size_t count = 0; count<NR_OF_BUYERS; ++count)
{
cout<<"Names of the buyer: ";
cin>>buyersN[count];
cout<<"Day of week buying:"
cin>>dOWeek[count];
cout<<"Number of icecream at R3 each";
cin>>noIcecream[count];
}
}
//I get lost here
void slips()
{
cout<<"-----------------"<<<<"SLIP"<<"--------------"<<endl;
}
for (size_t count=0; count<NR_OF_BUYERS; ++count)
}
};
int main()
{
iceCreamTruck e1;
e1.getBuyersDetails();
e1.slips();
}
OUTPUT:
Lets assume Thomas bouht 1 icecream Monday and Wednesday aT R3 each. And Luke bought 1 n Tuesday. Slip shoud look like below
--------------Slip -------------
Name: Thomas
Amount of ice cream bought: 2 @ R3 each Total: R 6
Day of Week: Monday , Wednesday
****************************************
Name: Luke
Amount of ice cream bought: 1 @ R3 each Total: R 3
Day of Week: Tuesday
I need to get the data that i wrote in array for buyersN, check hw many times the buyer appears in the array of 3. How many iceCream they bought and on which day. Maybe i did the getBuyersDetails() function wrong. How would you do it
#include <iostream>
#include <string>
#include <iomanip>
class iceCreamTruck
{
private:
staticconst size_t NR_OF_BUYERS = 3;
std::string buyersN[NR_OF_BUYERS];
std::string dOWeek[NR_OF_BUYERS];
int noIcecream[NR_OF_BUYERS] = {0} ;
staticconstexprdouble price = 3.00 ;
public:
void getBuyersDetails()
{
for( size_t count = 0; count < NR_OF_BUYERS; ++count )
{
std::cout << "names of the buyer: ";
std::cin >> buyersN[count] ;
std::cout << "Day of week: " ;
std::cin >> dOWeek[count];
std::cout << "Number of icecream at R3 each: ";
std::cin >> noIcecream[count];
}
}
//I get lost here
void slips()
{
std::cout<<"----------------- SLIP --------------\n\n" ;
for( size_t count = 0; count < NR_OF_BUYERS; ++count )
{
const std::string& name = buyersN[count] ;
if( !name.empty() ) // if this is a name that was not already processed
{
std::cout << "Name: " << name << '\n' ;
int num_ice_creams = noIcecream[count] ;
// iterate through the array to see if this name appears again
for( size_t i = count+1; i < NR_OF_BUYERS; ++i ) if( buyersN[i] == name )
num_ice_creams += noIcecream[i] ;
std::cout << "number of ice_creams: " << num_ice_creams << " total price: "
<< std::fixed << std::setprecision(2) << num_ice_creams * price << '\n' ;
std::cout << "day of week: " << dOWeek[count] ;
// iterate through the array to see if this name appears again
for( size_t i = count+1; i < NR_OF_BUYERS; ++i ) if( buyersN[i] == name )
{
std::cout << ' ' << dOWeek[i] ;
buyersN[i] = "" ; // we are done with this name, we don't want to process it again
}
std::cout << "\n\n" ;
}
}
}
};
int main()
{
iceCreamTruck e1;
e1.getBuyersDetails();
e1.slips();
}