Question

Use C++ Design a class to store measurements. The class should have two data items, feet...

Use C++

Design a class to store measurements. The class should have two data items, feet and inches, both integers. The class must make sure that the number of inches never gets below zero or above 11. If inches is outside that range, adjust feet accordingly. (Yes this means feet might be a negative number.)

Create a default constructor and one which receives one integer, a number of inches.

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

CODE IN C++ :

#include <iostream>
using namespace std;

class measurement{
public:
int feet ;
int inches ;
measurement() //this is the default constructor which initializes the value of feet and inches to 0 //
{
feet = 0 ;
inches = 0;
}
measurement(int inches , int feet) //this is the constructor which receives two int values which will be assigned to inches and feet based upon the conditions//
{
if( inches > 11)
{
int a = inches/12 ;
int b = inches%12;
this->feet = feet + a ;
this->inches = inches + b ;
}
else if(inches >= 0 && inches <= 11) // checking the range in which inches lie because it should always be greater than 0 as mentioned in the question
{
this->inches = inches ;
this->feet = feet ;
}
}
};

All the necessary comments have been added for your better understanding.

Hope this solves your doubt. Thank you :)

Add a comment
Know the answer?
Add Answer to:
Use C++ Design a class to store measurements. The class should have two data items, feet...
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
  • Please write the program in C++ Problem Description: Design a class called Date. The class should...

    Please write the program in C++ Problem Description: Design a class called Date. The class should store a date in three integers: month, day, and year.     Create the necessary set and get methods.       Design member functions to return the date as a string in the following formats:                                     12/25/2012                                     December 25, 2012                                     25 December 2012 Input Validation: Do not accept values for day greater than 30 or less than 1. Do not accept values for month...

  • In C++ Write a program that contains a BankAccount class. The BankAccount class should store the...

    In C++ Write a program that contains a BankAccount class. The BankAccount class should store the following attributes: account name account balance Make sure you use the correct access modifiers for the variables. Write get/set methods for all attributes. Write a constructor that takes two parameters. Write a default constructor. Write a method called Deposit(double) that adds the passed in amount to the balance. Write a method called Withdraw(double) that subtracts the passed in amount from the balance. Do not...

  • Using C++ Design a class called Numbers that can be used to translate integers in the range 0 to ...

    Using C++ Design a class called Numbers that can be used to translate integers in the range 0 to 9999 into an English description of the number. The class should have a single integer member variable: int number; and a static array of string objects that specify how to translate the number into the desired format. For example, you might use static string arrays such as: string lessThan20[20] = {"zero", "one", ..., "eighteen", "nineteen"}; string hundred = "hundred"; string thousand...

  • So far I have this code but I'm not sure if it's right or how to...

    So far I have this code but I'm not sure if it's right or how to finish it. #include "distance.h" #include <iostream> #include <iomanip> #include <string> using namespace std; Distance::Distance() { feet = 0; miles = 0; yards = 0; inches = 0; } Distance::Distance(int inch) {    } Distance::Distance(int m, int y, int f, double i) { if(m < 0 || y < 0 || f < 0) { feet = 0; miles = 0; yards = 0; }...

  • C++ FanClass.cpp Design a class named Fan to represent a fan. The class contains: Private section:...

    C++ FanClass.cpp Design a class named Fan to represent a fan. The class contains: Private section: An integer data field name speed that specifies the speed of the fan (1, 2, 3 or custom) A bool data field named on that specified whether the fan is on by default. A double data field named radius that specifies the radius of the fan A string data field named color that specifies the color of the fan. Public section: - Declare the...

  • Design a class called NumDays. The class’ purpose is to store a value that represents a...

    Design a class called NumDays. The class’ purpose is to store a value that represents a number of work hours and convert it to a number of days. For example, 8 hours would be converted to 1 day, 12 hours would be converted to 1.5 days, and 18 hours would be converted to 2.25 days. The class should have a constructor that accepts a number of hours, as well as member functions for storing and retrieving the hours and days....

  • C++ design a class named Technician that contains private data members to store the following: -technician's...

    C++ design a class named Technician that contains private data members to store the following: -technician's name (a string) - number of service calls - total time of all service calls - average service call time the technician class should also have the following public member functions: - a constructor function that initializes all data members by obtaining their values from the users. with the exception of the average service call time which will be calculated as: total_time/number_of_call - a...

  • Write a program in C++ that uses a class template to create a set of items....

    Write a program in C++ that uses a class template to create a set of items. . . The Problem Write program that uses a class template to create a set of items. The program should: 1. add items to the set (there shouldn't be any duplicates) Example: if your codes is adding three integers, 10, 5, 10, then your program will add only two values 10 and 5 Hint: Use vectors and vector functions to store the set of...

  • MAKE IT DIFFERENT WAYS TO RUN IT: Design an application for each of the following problems...

    MAKE IT DIFFERENT WAYS TO RUN IT: Design an application for each of the following problems writing the pseudocode for each; include a UML diagram if appropriate. Be sure to follow the CSI 117 Style Criteria for naming conventions, class diagrams, pseudocode, keywords, and operators. 1. Wood Trim, Inc. wants a program that will allow its sales clerks to enter the length (in feet) of the trim ordered by a customer and the price of one foot of trim. Design...

  • This is JAVA language Create a .java class called MoreArrayFun.java with only a main method. This...

    This is JAVA language Create a .java class called MoreArrayFun.java with only a main method. This program will use the ArrayManager class. The final version of the program is described below, but initially use it to test your ArrayManager class as you write it. Complete the ArrayManager class as specified below: The class will have exactly two instance variables:  An array of integers  A count of the number of elements currently in the array The class will have...

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