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.
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 :)
Use C++ Design a class to store measurements. The class should have two data items, feet...
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 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...
C++ please, thank you! Design a class named ArrayClass that has an array of floating-point numbers. The constructor should accept an integer argument and allocate the array on the heap to hold that many numbers. The default constructor should allocate an array that can hold one number. When the user attempts to store items, you must make a copy constructor that correctly produces a new copy of an ArrayClass object from an old one. If the user attempts to store...
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...
Program Description: Design a class named 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: 3/29/1988 29 MARCH 1988 MARCH 29, 1988 Input Validation: Do not accept values for day greater than 31 or less than 1. Do not accept values for month greater than 12 or less than 1. Do...
In C++: Implement a class Polynomial that uses a dynamic array of doubles to store the coefficients for a polynomial. This class does not need the method the overloaded += operator. Your class should have the following methods: Write one constructor that takes an integer n for the degree of a term and a double coefficient c for the coefficient of the term and creates the polynomial c x^n. (This constructor can be given default arguments easily to have a...
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;
}...
Course Class Create a class called Course. It will not have a main method; it is a business class. Put in your documentation comments at the top. Be sure to include your name. Course must have the following instance variables named as shown in the table: Variable name Description crn A unique number given each semester to a section (stands for Course Registration Number) subject A 4-letter abbreviation for the course (e.g., ITEC, PHED, CHEM) number A 4-digit number associated...
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...
This is a C++ program Instructions Design a class named PersonData with the following member variables declared as strings: lastName firstName address city state zip phone Create 3 constructors; a default constructor, a constructor that accepts the first and last name member variables, and a constructor that accepts all member variables. Write the appropriate accessor/getter and mutator/setter functions for these member variables. Create a method within this class called getFullName() that returns the person's first and last names as a...