LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-25-2006, 07:26 PM   #1
k1ll3r_x
Member
 
Registered: Sep 2004
Location: Laredo, TX
Distribution: Debian 11
Posts: 164

Rep: Reputation: 30
c++ class issue


ok, im taking a c++ class in college and i've always had trouble with classes, so far, i kind of understood it good to the point that i got my code going, but when i compile it, something happens, i dunno why, im using that visual c++ since im at home and using my pc not my laptop cus they stole it.
If someone could help me out with this id really appreciate, it could be the headings but i dunno.
here are the class, .h file and the test driver

Invoice.h

Code:
#include <iostream>
#include <string>
using std::string;
class Invoice
{
	
public:

Invoice(string, string, int, int)

void setPartNumber(string);
string getPartNumber();

void setPartDes(string);
string getPartDesc();

void setQuantity(int);
int getQuantity;

void setPrice(int);
int getPrice();

int getInvoiceAmount();

private:

	string PartNumber;
	string PartDesc;
	int Quantity;
	int Price;
};
Invoice.cpp
Code:
#include <iostream>
#include <string>
using std::string;

#include "invoice.h"


Invoice :: Invoice(string part_number, string part_desc, int q, int p)
{
	setPartNumber(part_number);
	setPartDesc(part_desc);
	setQuantity(q);
	setPrice(p);
}



void Invoice :: setPartNumber(string part_number)
{
	PartNumber = part_number;
}

string Invoice :: getPartNumber()
{
	return PartNumber;
}



void Invoice :: setPartDesc(string part_desc)
{
	PartDesc = part_desc;
}

string Invoice :: getPartDesc()
{
	return PartDesc;
}


void Invoice :: setQuantity(int q)
{
	Quantity = q;
}
int Invoice :: getQuantity()
{
	return Quantity;
}


void Invoice :: setPrice(int p)
{
	Price = p;
}
int Invoice :: getPrice()
{
	return p;
}

int Invoice :: getInvoiceAmount()
{
	return (Quantitie * Price);
}
test_invoice.cpp
Code:
#include <iostream>
using std::cout;
using std::endl;
#include "invoice.h"

int main()
{
	Invoice MyInvoice1("Device 1", "Dell Laptop", 5, 877);
	Invoice MyInvoice2("Device 2", "apple ipod", 7, 432);

	cout << "The total price of my first Invoice is: $"<< myInvoice1.getInvoiceAmount() << endl;
	cout << "The total price of my second Invoice is: $"<< myInvoice2.getInvoiceAmount() << endl;

	return 0;
}
Well if someone could help me out, id really appreciate. thanx

Last edited by k1ll3r_x; 09-25-2006 at 07:27 PM.
 
Old 09-25-2006, 09:49 PM   #2
pankaj99
Member
 
Registered: Mar 2006
Location: India
Distribution: Fedora
Posts: 47

Rep: Reputation: 15
you are missing a ';' at the end of declaration of Invoice in Invoice.h.
change it to:
Invoice(string, string, int, int);
 
Old 09-25-2006, 09:51 PM   #3
pankaj99
Member
 
Registered: Mar 2006
Location: India
Distribution: Fedora
Posts: 47

Rep: Reputation: 15
next time, please post what is the exact problem you are facing
or the output of the compiler error messages.
 
Old 09-25-2006, 10:27 PM   #4
k1ll3r_x
Member
 
Registered: Sep 2004
Location: Laredo, TX
Distribution: Debian 11
Posts: 164

Original Poster
Rep: Reputation: 30
I changed it and this is my compiler output, im sorry i hadnt put that before, also you should know its better to put both posts in one. Its easier to read and time saving.
Code:
1>------ Build started: Project: Project, Configuration: Debug Win32 ------
1>Compiling...
1>invoice_test.cpp
1>.\invoice_test.cpp(11) : error C2065: 'myInvoice1' : undeclared identifier
1>.\invoice_test.cpp(11) : error C2228: left of '.getInvoiceAmount' must have class/struct/union
1>        type is ''unknown-type''
1>.\invoice_test.cpp(12) : error C2065: 'myInvoice2' : undeclared identifier
1>.\invoice_test.cpp(12) : error C2228: left of '.getInvoiceAmount' must have class/struct/union
1>        type is ''unknown-type''
1>Invoice.cpp
1>.\Invoice.cpp(11) : error C3861: 'setPartDesc': identifier not found
1>.\Invoice.cpp(30) : error C2039: 'setPartDesc' : is not a member of 'Invoice'
1>        c:\documents and settings\hp_owner\my documents\visual studio 2005\projects\project\project\invoice.h(5) : see declaration of 'Invoice'
1>.\Invoice.cpp(31) : error C2365: 'setPartDesc' : redefinition; previous definition was 'formerly unknown identifier'
1>.\Invoice.cpp(32) : error C2065: 'PartDesc' : undeclared identifier
1>.\Invoice.cpp(46) : error C2063: 'Invoice::getQuantity' : not a function
1>.\Invoice.cpp(57) : error C2065: 'p' : undeclared identifier
1>.\Invoice.cpp(62) : error C2065: 'Quantitie' : undeclared identifier
1>Generating Code...
1>Build log was saved at "file://c:\Documents and Settings\HP_Owner\My Documents\Visual Studio 2005\Projects\Project\Project\Debug\BuildLog.htm"
1>Project - 11 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
also if anyone is as a guest and could help me but is not registered, please add me to k1ll3r_x@hotmail.com, id really appreciate the help.

Last edited by k1ll3r_x; 09-25-2006 at 10:30 PM.
 
Old 09-25-2006, 11:04 PM   #5
pankaj99
Member
 
Registered: Mar 2006
Location: India
Distribution: Fedora
Posts: 47

Rep: Reputation: 15
Put in some effort to debug the code yourself.
It took me 2 min to correct it.
Below is the code with all files put into one.


Code:
#include <iostream>
#include <string>
using namespace std;



class Invoice
{
	
public:

Invoice(string, string, int, int);

void setPartNumber(string);
string getPartNumber();

void setPartDesc(string);
string getPartDesc();

void setQuantity(int);
int getQuantity();

void setPrice(int);
int getPrice();

int getInvoiceAmount();

private:

	string PartNumber;
	string PartDesc;
	int Quantity;
	int Price;
};





Invoice :: Invoice(string part_number, string part_desc, int q, int p)
{
	setPartNumber(part_number);
	setPartDesc(part_desc);
	setQuantity(q);
	setPrice(p);
}



void Invoice :: setPartNumber(string part_number)
{
	PartNumber = part_number;
}

string Invoice :: getPartNumber()
{
	return PartNumber;
}



void Invoice :: setPartDesc(string part_desc)
{
	PartDesc = part_desc;
}

string Invoice :: getPartDesc()
{
	return PartDesc;
}


void Invoice :: setQuantity(int q)
{
	Quantity = q;
}
int Invoice :: getQuantity()
{
	return Quantity;
}


void Invoice :: setPrice(int p)
{
	Price = p;
}
int Invoice :: getPrice()
{
	return Price;
}

int Invoice :: getInvoiceAmount()
{
	return (Quantity * Price);
}

int main()
{
	Invoice MyInvoice1("Device 1", "Dell Laptop", 5, 877);
	Invoice MyInvoice2("Device 2", "apple ipod", 7, 432);

	cout << "The total price of my first Invoice is: $"<< MyInvoice1.getInvoiceAmount() << endl;
	cout << "The total price of my second Invoice is: $"<< MyInvoice2.getInvoiceAmount() << endl;

	return 0;
}
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Does derivated class inherit base class destructor (constructor)? kornerr Programming 2 08-23-2006 08:05 AM
Which C++ editor in Linux has the class view/class browser feature imaginationworks Programming 7 05-21-2006 11:09 PM
BlackBox.class & VerifierBug.class virus ??? dalek Linux - Security 4 02-29-2004 08:55 AM
Inheriting class members (Qt C++, QApplication class) jtshaw Programming 2 01-15-2004 11:52 AM
c++ : regarding (inheritence)base class and derived class edreddy Programming 6 07-31-2002 06:33 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:35 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration