Question

Create a class called Skateboard. Skateboard has 3 private member variables and 3 public member functions.(C++,...

Create a class called Skateboard. Skateboard has 3 private member variables and 3 public member functions.(C++, Visual Studios)

Skateboard has the following 3 private member variables:

1) the brand of the skateboard (such as “Sector 9”)      

2) the model of the skateboard (such as “Hot Steppa”)

3) the length of the skateboard in inches (such as “22”)

Skateboard has the following 3 public member functions:

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 (use whatever format you prefer)

a member function named set which does not have any return value but has 3 input parameters which are 1) skateboard brand 2) skateboard model and 3) length of the skateboard. This function will set the value of each member variable with each parameter given.

For example, consider the following code.
Skateboard s;

s.set(“Sector 9”, “Hot Steppa”, 22);
The above line should set the three member variables’ values accordingly.

a member function named isLongBoard which returns true if the skateboard has a length of more than 28 inches. Otherwise, it returns false.

In the main function, create a vector of 4 Skateboards named skateboardCollection.

Using a for loop and cin, ask the user to enter the brand, model, and length of each skateboard and populate each element in the vector using 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.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer

#include <iostream>
#include <string>
using namespace std;
class Skateboard
{
string brand,model;
int length;
public:
void print()
{
cout<<"\nBrand : "<<brand;
cout<<"\nModel : "<<model;
cout<<"\nLength(inches) : "<<length;
}
void set(string b,string m,int l)
{
brand=b;
model=m;
length=l;
}
bool isLongBoard()
{
if(length>28)
return true;
else
return false;
}
};
int main()
{
string b,m;
int i,len;
Skateboard skateboardCollection[4];
for(i=0;i<4;i++)
{
cout<<"\n----------------------------SKATEBOARD "<<i+1<<"----------------------------";
cout<<"\nEnter Brand : ";cin>>b;
cout<<"\nEnter Model : ";cin>>m;
cout<<"\nEnter Length(inches) : ";cin>>len;
skateboardCollection[i].set(b,m,len);
}
for(i=0;i<4;i++)
{
cout<<"\n----------------------------SKATEBOARD "<<i+1<<"----------------------------";
skateboardCollection[i].print();
if(skateboardCollection[i].isLongBoard()==true)
cout<<"\nLong Board Status : TRUE";
else
cout<<"\nLong Board Status : FALSE";
}
return 0;
}

OUTPUT

Default Term sh-4.2$ main -SKATEBOARD 1---- Enter Brand : abc Enter Model : abc1 Enter Length(inches) 23 -SKATEBOARD 2---- :

Add a comment
Know the answer?
Add Answer to:
Create a class called Skateboard. Skateboard has 3 private member variables and 3 public member functions.(C++,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Create a class called Pair that has two public integer member variables named "a" and "b",...

    Create a class called Pair that has two public integer member variables named "a" and "b", and a public member function named sum() that has no arguments but adds the two member variables together and returns their sum.

  • C++ Visul Studio Create a class named Vehicle. The class has the following five member variables:...

    C++ Visul Studio Create a class named Vehicle. The class has the following five member variables: • Vehicle Name • Vehicle number • Sale Tax • Unit price • Total price Include set (mutator) and get (accessor) functions for each field except the total price field. The set function prompt the user for values for each field. This class also needs a function named computePrice() to compute the total price (quantity times unit price + salesTax) and a function to...

  • Programming: Create a class called City with two public variables: a string to store the name...

    Programming: Create a class called City with two public variables: a string to store the name of the city and a float to store the average temperature in Fahrenheit. Create one object of the class that you create and ask the user to enter the city name and the average temperature in Fahrenheit. Store these in the object of the class that you create. Then display the contents of the class. Once that is working, make the variables private and...

  • Design a bank account class named Account that has the following private member variables:

    Need help please!.. C++ programDesign a bank account class named Account that has the following private member variables: accountNumber of type int ownerName of type string balance of type double transactionHistory of type pointer to Transaction structure (structure is defined below) numberTransactions of type int totalNetDeposits of type static double.The totalNetDeposits is the cumulative sum of all deposits (at account creation and at deposits) minus the cumulative sum of all withdrawals. numberAccounts of type static intand the following public member...

  • C++ Define the class HotelRoom. The class has the following private data members: the room number...

    C++ Define the class HotelRoom. The class has the following private data members: the room number (an integer) and daily rate (a double). Include a default constructor as well as a constructor with two parameters to initialize the room number and the room’s daily rate. The class should have get/set functions for all its private data members [3pts]. The constructors and the set functions must throw an invalid_argument exception if either one of the parameter values are negative. The exception...

  • C++ write a class “Dog” with a private int field called months and two public member...

    C++ write a class “Dog” with a private int field called months and two public member functions setAge and GetStage. setAge takes as argument monthsToSet and sets the member field months. setAge returns void. getStage is a const member function that takes no argument and returns a string “Puppy” if the dog is less than 9 months old, “Adolescence” if more than 9 and less than 13 months, “Adulthood” if more than 13 and less than 60 months and “Senior”...

  • Create a class named Date in C++ Class has 3 private data items (name the data...

    Create a class named Date in C++ Class has 3 private data items (name the data items month, day, year) int month int day int year Member functions ‘getters’   a getter for each data item Use ‘get’ and the data items name The data item name must be capitalized Return the data item Example: int getMonth()        {return month;} ‘setters’   a setter for each data item Use ‘set’ and the data items name The data item name must be capitalized Change...

  • Design and implement a C++ class called Date that has the following private member variables month...

    Design and implement a C++ class called Date that has the following private member variables month (int) day (nt) . year (int Add the following public member functions to the class. Default Constructor with all default parameters: The constructors should use the values of the month, day, and year arguments passed by the client program to set the month, day, and year member variables. The constructor should check if the values of the parameters are valid (that is day is...

  • Question 65 (15 points) Code a Car class with 3 private member variables make, speed, and yearMod...

    Use C++ Question 65 (15 points) Code a Car class with 3 private member variables make, speed, and yearModel. In the public section, one constructor passed the yearModel and make and three accesor member methods. Member functions and variables should be in ascending alphabetic order. Question 65 (15 points) Code a Car class with 3 private member variables make, speed, and yearModel. In the public section, one constructor passed the yearModel and make and three accesor member methods. Member functions...

  • FOR C++ PLEASE Create a class called "box" that has the following attributes (variables): length, width,...

    FOR C++ PLEASE Create a class called "box" that has the following attributes (variables): length, width, height (in inches), weight (in pounds), address (1 line), city, state, zip code. These variables must be private. Create setter and getter functions for each of these variables. Also create two constructors for the box class, one default constructor that takes no parameters and sets everything to default values, and one which takes parameters for all of the above. Create a calcShippingPrice function that...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT