Assignment:
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.
Overload the following operators: addition, subtraction, equality, inequality, incrementation (both pre and post) (should add one to inches), and output (in the form of: F’I”)
Code:
#include <iostream>
using namespace std;
class measurements {
private:
int inches;
double feet;
public:
int GetInches() {return inches;}
double GetFeet() {return feet;}
measurements();
measurements(int,double);
measurements operator+(const measurements& value);
measurements operator-(const measurements& value);
measurements& operator++(); //pre
measurements operator++(int); //post
friend bool operator==(const measurements& lhs, const measurements& rhs);
friend bool operator!=(const measurements& lhs, const measurements& rhs);
friend ostream& operator<< (ostream &out, const measurements& value);
};
measurements::measurements(){
inches = 1;
feet = 1;
}
measurements::measurements(int inchs, double ft){
inches = inchs;
feet = ft;
}
ostream &operator<< (ostream& out, const measurements& value)
{
out << "F:" <<value.feet << "'";
out << "I:" <<value.inches << " \" ";
return out;
}
double Normalize(double feet, int inches){
if(inches == 0 || inches < 0){
cout<< "Enter a number bigger than zero!"<< endl;
}
else{
while(inches > 11){
inches = inches - 12;
++feet;
return feet;
}
if((inches > 0) & (inches < 12)){
feet = inches % 12;
return feet;
}
}
}
bool operator==(const measurements& lhs, const measurements& rhs)
{
return(lhs.inches == rhs.inches && lhs.feet == rhs.feet);
}
bool operator!=(const measurements& lhs, const measurements& rhs)
{
return(lhs.inches != rhs.inches) || (lhs.feet != rhs.feet);
}
measurements& measurements::operator++(){
inches++;
return *this;
}
measurements measurements::operator++(int){
measurements temp;
temp.inches = inches;
inches++;
return temp;
}
measurements measurements::operator+(const measurements& value)
{
measurements temp;
temp.inches = value.inches + value.inches;
return temp;
}
measurements measurements::operator-(const measurements& value)
{
measurements temp;
temp.inches = value.inches - value.inches;
return temp;
}
int main(){
int inches;
double feet = 0;
cout<<"Enter an integer number of inches: ";
cin>> inches;
measurements Msrmnt1(inches, feet);
feet = Normalize(feet,inches);
cout<<"The amount of feet is: "<<feet<<endl;
}
Im getting a LNK2019 error and an LNK1120 errors:
Error 1 error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup
Error 2 error LNK1120: 1 unresolved externals
I have no idea what is causing them. Any insight/help would be greatly appreciated!