Question: In the main function, create a vector of 2 Skateboards named skateboardCollection. Using a for loop and cin (NOT getline), ask the user to enter

In the main function, create a vector of 2 Skateboards named skateboardCollection. Using a for loop and cin (NOT getline), ask the user to enter the brand, model, and length of each skateboard and populate each element in the vector using the set member function.

After that display all of the data in the vector via a well-designed loop using the print member function. Also display if the board is a longboard as determined by the isLongBoard function, like so:

a member function named print which does not have any return value or input parameter. It should display to the screen all 3 member variables in the following way: brand: thebrand model: themodel length: the_length longBoard: 0/1

Where the_brand is the value of brand, the_model is the value of model, and the_length is the value of length and 0/1 is the value of is long board (0 if false, 1 if true)

sample output for one skateboard:

brand: Sector9 model: HotSteppa length: 22 isLongBoard: 0

This is my current code: (It is not displaying any output so I know I've done something or more than one thing wrong in the code.)

#include #include #include using namespace std;

class Skateboard { private: string brand; string model; int length;

public: void Print(); void Set(string skateBrand, string skateModel, int skateLength); bool isLongBoard() const; };

void Skateboard::Print() { cout << "brand: " << brand << endl; cout << "model: " << brand << endl; cout << "length: " << brand << endl; }

void Skateboard::Set(string skateBrand, string skateModel, int skateLength) { brand = skateBrand; model = skateModel; length = skateLength; }

bool Skateboard::isLongBoard() const { if (length > 28) { return 1; //cout << "isLongBoard: " << 1 << endl; } else { return 0; //cout << "isLongBoard: " << 0 << endl; } }

int main() { vector skateboardCollection; Skateboard s; string userBrand, userModel; int userLength;

for (int i = 0; i < 2; i++) { cin >> userBrand >> userModel >> userLength;

//set variables using set method on skateboard object s s.Set(userBrand, userModel, userLength);

//push back variables skateboardCollection.push_back(&s);

}

//to print for (int i = 0; i < 2; i++) { skateboardCollection[i]->Print(); cout << "isLongBoard: " << skateboardCollection[i]->isLongBoard() << endl; } system("pause"); return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!