Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Development Of Knowledge Framework For Affective Content Analysis

Authors: Swarnangini Sinha

1st Edition

B0CQJ13WZ1, 979-8223977490

More Books

Students also viewed these Databases questions

Question

8-6 Who poses the biggest security threat: insiders or outsiders?

Answered: 1 week ago