Like Tree2Likes
  • 2 Post By jimblumberg

LNK2019 error

This is a discussion on LNK2019 error within the C++ Programming forums, part of the General Programming Boards category; Assignment: Design a class to store measurements. The class should have two data items, feet and inches, both integers. The ...

  1. #1
    Registered User
    Join Date
    Jul 2013
    Posts
    6

    LNK2019 error

    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!
    Last edited by pochta; 07-08-2013 at 07:17 PM.

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    2,919
    Every C++ program must have a main() function. Where is your's?

    Jim

  3. #3
    Registered User
    Join Date
    Jul 2013
    Posts
    6
    Ok now its there. I edited the first post. The errors are gone but it's not working the way it should be. Namely the "Normalize" function is not working the way I intended it to. It keeps giving me back 1 foot regardless of the number of inches.

  4. #4
    Registered User
    Join Date
    May 2010
    Posts
    2,919
    Also posted here.

    Jim
    Salem and stahta01 like this.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Error LNK2019
    By Mycroft Holmes in forum C++ Programming
    Replies: 9
    Last Post: 04-17-2013, 08:17 AM
  2. Replies: 7
    Last Post: 10-27-2012, 03:55 PM
  3. Help on error LNK2019
    By jlbfunes in forum C++ Programming
    Replies: 5
    Last Post: 08-21-2008, 09:19 AM
  4. I got error LNK2019
    By Daggio in forum Windows Programming
    Replies: 3
    Last Post: 03-14-2008, 03:29 AM
  5. Main.obj : error LNK2019:
    By thestien in forum Game Programming
    Replies: 6
    Last Post: 12-18-2007, 05:39 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21