8 Replies - 400 Views - Last Post: 30 July 2014 - 02:48 AM Rate Topic: -----

#1 liubei  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 29-July 14

Help on Class and Client Program

Posted 29 July 2014 - 07:34 PM

I am working on a program that allows the user to input the dimensions of a box, then calculate from the values an invoice of the costs of said box.
currently I'm getting these errors:

Error 1 error LNK2019: unresolved external symbol "public: __thiscall GiftWrap::GiftWrap(double,double)" (??0GiftWrap@@QAE@NN@Z) referenced in function _main E:\C++ Programming\CS 135\LAB7 - Program3\LAB7 - Program3\LAB7 - program3.obj LAB7 - Program3

and

Error 2 error LNK1120: 1 unresolved externals E:\C++ Programming\CS 135\LAB7 - Program3\Debug\LAB7 - Program3.exe 1 1 LAB7 - Program3
Some of the functions that I was required to make as per the instructions for the lab I found to be redundant so I commented them out for the time being.


Header File:
-------------
#include <iostream>
#include <string>

using namespace std;

/*
			UML
-----------------------------
|		GiftWrap			|
-----------------------------
| -length:double			|
| -width:double				|
| -height:double			|
| -taxRate:double			|
| -pricePerInch:double		|
-----------------------------
| +GiftWrap()				|
| +GiftWrap(taxRate:double, |
|	pricePerInch:double)	|
|							|
| +setlength(double)		|
| +setwidth(double)			|
| +setheight(double)		|
| +setpricePerInch(double)	|
| +settaxRate(double)		|
|							|
| +getlength(double)		|
| +getwidth(double)			|
| +getheight(double)		|
| +getpricePerInch(double)	|
| +gettaxRate(double)		|
|							|
| +calcSubtotal()			|
| +calcTax()				|
| +calcTotal()				|
-----------------------------
*/

class GiftWrap{
private:
	double length, width, height, taxRate, pricePerInch;

public:
	GiftWrap();
	GiftWrap(double taxRate, double pricePerInch);

	double setlength(double);
	double setwidth(double);
	double setheight(double);
	double setpricePerInch();
	double settaxRate();

	double getlength();
	double getwidth();
	double getheight();
	double getpricePerInch();
	double gettaxRate();

	double calcSubtotal(double, double, double, double);
	double calcTax(double);
	double calcTotal(double, double);
};





Implementation File:
--------------------
#include "program3.h"

GiftWrap::GiftWrap() // set values for member variables
{
	pricePerInch = 0.036;
	taxRate = 0.08;
}

/*
GiftWrap::GiftWrap(double t, double p) // user inputted taxRate and pricePerInch
{
	t = taxRate;
	p = pricePerInch;
}
*/

double GiftWrap::setlength(double l)
{
	l = length;
	return length;
}
double GiftWrap::setwidth(double w)
{
	w = width;
	return width;
}
double GiftWrap::setheight(double h)
{
	h = height;
	return height;
}

/*
double GiftWrap::setpricePerInch()
{
	
}
double GiftWrap::settaxRate()
{

}
*/

double GiftWrap::getlength()
{
	return length;
}
double GiftWrap::getwidth()
{
	return width;
}
double GiftWrap::getheight()
{
	return height;
}
double GiftWrap::getpricePerInch()
{
	return pricePerInch;
}
double GiftWrap::gettaxRate()
{
	return taxRate;
}

double GiftWrap::calcSubtotal(double length, double width, double height, double pricePerInch)
{
	double area;
	double subtotal;

	area = (2 * length * width) + (2 * length * height) + (2 * width * height);
	subtotal = area * pricePerInch;

	return subtotal;

}

double GiftWrap::calcTax(double subtotal)
{
	double tax = subtotal * taxRate;
	return tax;
}
double GiftWrap::calcTotal(double subtotal, double tax)
{
	double total;
	total = subtotal + tax;
	return total;
}



Main Function:
---------------
#include "program3.h"

int main()
{
	int selection;
	string store = "Sally’s Gifts";
	GiftWrap sallys(.0925, .0025);


	cout << "GIFT WRAP INVOICE GENERATOR\n"
		<< "--------------------------------\n"
		<< "1)Generate Gift Wrap Invoice\n"
		<< "2)Generate Gift Wrap Invoice for bargain size\n"
		<< "3)Quit\n";
	cin >> selection;

	if (selection == 1)
	{
		double l;
		cout << "What's the length of your gift? ";
		cin >> l;
		sallys.setlength(l);

		double w;
		cout << "What's the width of your gift? ";
		cin >> w;
		sallys.setwidth(w);

		double h;
		cout << "What's the height of your gift? ";
		cin >> h;
		sallys.setwidth(h);

	}
	while (selection < 1 || selection > 3)
	{
		cout << "INVALID SELECTION! Choose another option: ";
		cin >> selection;
	}
	
	cout << "GIFT WRAP INVOICE - Sally's Gifts\n"
		<< "----------------------------------\n";
	cout << "Box Length : " << sallys.getlength() << endl;
	cout << "Box Width : " << sallys.getwidth() << endl;
	cout << "Box Height : " << sallys.getheight() << endl;
	cout << "Price Per Inch : " << sallys.getpricePerInch() << endl;
	
	double l = sallys.getlength();
	double w = sallys.getwidth();
	double h = sallys.getheight();
	double p = sallys.getpricePerInch();
	double t = sallys.gettaxRate();

	cout << "SUBTOTAL : " << sallys.calcSubtotal(l, w, h, p) << endl;
	cout << "TAX : " << sallys.calcTax(t) << endl;

	double subtotal = sallys.calcSubtotal(l, w, h, p);

	cout << "----------\n"
		<< "TOTAL : " << sallys.calcTotal(subtotal, t) << endl;



	system("pause");
	return 0;
}


Is This A Good Question/Topic? 0
  • +

Replies To: Help on Class and Client Program

#2 jimblumberg  Icon User is online

  • member icon


Reputation: 4293
  • View blog
  • Posts: 13,462
  • Joined: 25-December 09

Re: Help on Class and Client Program

Posted 29 July 2014 - 08:44 PM

Quote

Error 1 error LNK2019: unresolved external symbol "public: __thiscall GiftWrap::GiftWrap(double,double)" (??0GiftWrap@@QAE@NN@Z) referenced in function _main E:\C++ Programming\CS 135\LAB7 - Program3\LAB7 - Program3\LAB7 - program3.obj LAB7 - Program3


Quote

Some of the functions that I was required to make as per the instructions for the lab I found to be redundant so I commented them out for the time being.


Looks to me like one of your redundant functions was not so redundant.

Jim
Was This Post Helpful? 0
  • +
  • -

#3 liubei  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 29-July 14

Re: Help on Class and Client Program

Posted 29 July 2014 - 08:58 PM

Yea, sorry. That was a dumb mistake, I found it out half an hour ago but I don't know how to edit my post so I couldn't update my fixes.

If I remove the comments from the constructor(double, double)
The error is gone but I ran into a new problem.

The program is outputting crazy numbers.
GIFT WRAP INVOICE GENERATOR
1)Generate Gift Wrap Invoice
2)Generate Gift Wrap Invoice for bargain size
3)Quit
1
What's the length of your gift? 10
What's the width of your gift? 10
What's the height of your gift? 10
GIFT WRAP INVOICE - Sally's Gifts
Box Length : -9.25596e+061
Box Width : -9.25596e+061
Box Height : -9.25596e+061
Price Per Inch : -9.25596e+061
SUBTOTAL : -4.75791e+186
TAX : 8.56729e+123
TOTAL : -4.75791e+186
Press any key to continue . . .

I know it's a problem with my set and get functions, the user input values are being read into the set functions.
Was This Post Helpful? 0
  • +
  • -

#4 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3667
  • View blog
  • Posts: 11,501
  • Joined: 05-May 12

Re: Help on Class and Client Program

Posted 29 July 2014 - 09:27 PM

Double check you your assignments in your setXXX() methods. The source and destination look to be reversed.
Was This Post Helpful? 1
  • +
  • -

#5 liubei  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 29-July 14

Re: Help on Class and Client Program

Posted 29 July 2014 - 09:39 PM

View PostSkydiver, on 29 July 2014 - 09:27 PM, said:

Double check you your assignments in your setXXX() methods. The source and destination look to be reversed.


You'll have to excuse me as the only other time I've done these set and get functions successfully was with strings on another project.
I used the exact same method on these functions unsuccessfully obviously.

So I have no past experience to go on to understand how it's reversed.
Was This Post Helpful? 0
  • +
  • -

#6 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3667
  • View blog
  • Posts: 11,501
  • Joined: 05-May 12

Re: Help on Class and Client Program

Posted 29 July 2014 - 09:49 PM

Let's take a quick look at your code:
double GiftWrap::calcTotal(double subtotal, double tax)
{
    double total;
    total = subtotal + tax;
    return total;
}



On line 4, why do you have total on the left side of the '='? Why not on the right side?

Once you formulate your answer for why, then look at your code for your setXXX() functions. Look at this for example:
double GiftWrap::setlength(double l)
{
    l = length;
    return length;
}


Why do you have l on the left side of the '='? Is that consistent with your reasoning for your calcTotal() function?
Was This Post Helpful? 1
  • +
  • -

#7 liubei  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 29-July 14

Re: Help on Class and Client Program

Posted 29 July 2014 - 10:06 PM

double GiftWrap::calcTotal(double subtotal, double tax)
{
    double total;
    subtotal + tax = total;
    return total;
}



Ah I see, if I flip the total to the right, the compiler gives me an error: expression must be a modifiable |value.

I'm guessing it's right the way I have it in calcTotal

void GiftWrap::setlength(double l)
{
	length = l;
}
void GiftWrap::setwidth(double w)
{
	width = w;
}
void GiftWrap::setheight(double h)
{
	height = h;
}


I've flipped them now and the results are better, length and width are reading what the user inputs. Except sallys.getheight() is still returning RAM values.

int main()
{
	int selection;
	string store = "Sally’s Gifts";
	GiftWrap sallys(.0925, .0025);
	GiftWrap sallys2();

	cout << "GIFT WRAP INVOICE GENERATOR\n"
		<< "--------------------------------\n"
		<< "1)Generate Gift Wrap Invoice\n"
		<< "2)Generate Gift Wrap Invoice for bargain size\n"
		<< "3)Quit\n";
	cin >> selection;

	if (selection == 1)
	{
		double length;
		cout << "What's the length of your gift? ";
		cin >> length;
		sallys.setlength(length);

		double width;
		cout << "What's the width of your gift? ";
		cin >> width;
		sallys.setwidth(width);

		double height;
		cout << "What's the height of your gift? ";
		cin >> height;
		sallys.setwidth(height);

	
		cout << "GIFT WRAP INVOICE - Sally's Gifts\n"
			<< "----------------------------------\n";
		cout << "Box Length : " << sallys.getlength() << endl;
		cout << "Box Width : " << sallys.getlength() << endl;
		cout << "Box Height : " << sallys.getheight() << endl;
		cout << "Price Per Inch : " << sallys.getpricePerInch() << endl;

		double l = sallys.getlength();
		double w = sallys.getwidth();
		double h = sallys.getheight();
		double p = sallys.getpricePerInch();
		double t = sallys.gettaxRate();

		cout << "SUBTOTAL : " << sallys.calcSubtotal(l, w, h, p) << endl;
		cout << "TAX : " << sallys.calcTax(t) << endl;

		double subtotal = sallys.calcSubtotal(l, w, h, p);

		cout << "----------\n"
			<< "TOTAL : " << sallys.calcTotal(subtotal, t) << endl;
	}
	while (selection < 1 || selection > 3)
	{
		cout << "INVALID SELECTION! Choose another option: ";
		cin >> selection;
	}

	system("pause");
	return 0;
}

Was This Post Helpful? 0
  • +
  • -

#8 liubei  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 29-July 14

Re: Help on Class and Client Program

Posted 29 July 2014 - 10:33 PM

Nevermind, the problem was that I called getlength when I should have called getwidth.
Was This Post Helpful? 0
  • +
  • -

#9 David W  Icon User is offline

  • DIC supporter
  • member icon

Reputation: 281
  • View blog
  • Posts: 1,788
  • Joined: 20-September 08

Re: Help on Class and Client Program

Posted 30 July 2014 - 02:48 AM

Take a simple example:

int a = 5, b = 6, c = 7, d;

// this is ok and will compile:
d = a + b + c;

// this is NOT ok and will NOT compile:
d + a = b + c; // bad line // why ? //


You had tried above ...

Quote

double GiftWrap::calcTotal(double subtotal, double tax)
{
    double total;
    subtotal + tax = total;
    return total;
}


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1