#include <iostream>
#include "Invoice.h"
using namespace std;
int main()
{
CInvoice Order;
Order.ProcessOrder();
Order.ShowOrder();
}
Error: 'CInvoice' was not declare in this scope
Page 1 of 113 Replies - 249 Views - Last Post: 30 December 2012 - 08:33 AM
#1
Error: 'CInvoice' was not declare in this scope
Posted 30 December 2012 - 01:18 AM
Replies To: Error: 'CInvoice' was not declare in this scope
#2
Re: Error: 'CInvoice' was not declare in this scope
Posted 30 December 2012 - 02:09 AM
Would you please post the exact error message as it appears in your development environment along with the line number it contains...
#3
Re: Error: 'CInvoice' was not declare in this scope
Posted 30 December 2012 - 02:30 AM
AKMafia001, on 30 December 2012 - 02:09 AM, said:
Would you please post the exact error message as it appears in your development environment along with the line number it contains...
Line 11 : error: 'CInvoice' was not declared in this scope
Line 11 : error: expected ';' before 'Order'
Line 14 : error: 'Order' was not declared in this scope
That the 3 error i get when i try to compile it
#4
Re: Error: 'CInvoice' was not declare in this scope
Posted 30 December 2012 - 03:00 AM
Well! The problem seems to be with the include file #include "Invoice.h"... It might not be included properly...
Are you using an IDE for your project? Does your header file exists in the current directory or the project directory?
Please post the class definition code... Use the code tags
Are you using an IDE for your project? Does your header file exists in the current directory or the project directory?
Please post the class definition code... Use the code tags
#5
Re: Error: 'CInvoice' was not declare in this scope
Posted 30 December 2012 - 03:01 AM
Edit: Double post...
This post has been edited by AKMafia001: 30 December 2012 - 03:02 AM
#6
Re: Error: 'CInvoice' was not declare in this scope
Posted 30 December 2012 - 05:36 AM
COde for car.cpp
code for car.h
code for customer.cpp
code for customer.h
code for invoice.cpp
code for invoice.h
code for rentdate.cpp
code for rentdate.h
Sorry about the long reply, i have all the source code. Advance thanks
// Car.cpp: implementation of the Car class.
#include <iostream>
#include <cstring>
#include<conio.h>
#include<stdio.h>
#include <cstdlib>
using namespace std;
#include "Car.h"
//--------------------------------------------------------------------
Car::Car()
{
setMakeModel("No Car Selected");
setCarYear(2000);
setCategory(1);
}
//--------------------------------------------------------------------
Car::Car(char *MM, int Y, int Cat)
{
setMakeModel(MM);
setCarYear(Y);
setCategory(Cat);
}
//--------------------------------------------------------------------
Car::~Car()
{
// delete [] MakeModel;
}
//--------------------------------------------------------------------
void Car::setMakeModel(const char *m)
{
MakeModel = new char[strlen(m) + 1];
strcpy(MakeModel, m);
}
//--------------------------------------------------------------------
char* Car::getMakeModel() const
{
return MakeModel;
}
//--------------------------------------------------------------------
void Car::setCarYear(const int y)
{
CarYear = y;
}
//--------------------------------------------------------------------
int Car::getCarYear() const
{
return CarYear;
}
//--------------------------------------------------------------------
void Car::setCategory(const int c)
{
Category = c;
}
//--------------------------------------------------------------------
int Car::getCategory() const
{
return Category;
}
//--------------------------------------------------------------------
code for car.h
#if !defined CAR_H
#define CAR_H
enum TCarType { ctEconomy = 1, ctCompact, ctStandard, ctFullSize, ctMiniVan, ctSUV };
class Car
{
public:
Car();
Car(char *MM, int Y, int Cat);
virtual ~Car();
void setMakeModel(const char *mm);
char* getMakeModel() const;
void setCarYear(const int y);
int getCarYear() const;
void setCategory(const int c);
int getCategory() const;
private:
char* MakeModel;
int CarYear;
int Category;
};
#endif // CAR_H
code for customer.cpp
//---------------------------------------------------------------------------
#include <iostream>
#include<conio.h>
#include<stdio.h>
#include <cstdlib>
#include <cstring>
using namespace std;
#pragma hdrstop
#include "Customer.h"
//---------------------------------------------------------------------------
char *Customer::FullName() const
{
char *FName = new char[40];
strcpy(FName, FirstName);
strcat(FName, " ");
strcat(FName, LastName);
return FName;
}
//---------------------------------------------------------------------------
Customer::Customer()
: ZIPCode(0)
{
FirstName = new char[20];
strcpy(FirstName, "John");
LastName = new char[20];
strcpy(LastName, "Doe");
Address = new char[40];
strcpy(Address, "123 Main Street Apt A");
City = new char[32];
strcpy(City, "Great City");
State = new char[30];
strcpy(State, "Our State");
}
//---------------------------------------------------------------------------
Customer::Customer(char * FName, char * LName)
: ZIPCode(0)
{
FirstName = new char[strlen(FName) + 1];
strcpy(FirstName, FName);
LastName = new char[strlen(LName) + 1];
strcpy(LastName, LName);
Address = new char[40];
strcpy(Address, "123 Main Street Apt A");
City = new char[32];
strcpy(City, "Great City");
State = new char[30];
strcpy(State, "Our State");
}
//---------------------------------------------------------------------------
Customer::Customer(char *FName, char *LName, char *Adr,
char *Ct, char *St, long ZIP)
: ZIPCode(ZIP)
{
FirstName = new char[strlen(FName) + 1];
strcpy(FirstName, FName);
LastName = new char[strlen(LName) + 1];
strcpy(LastName, LName);
Address = new char[40];
strcpy(Address, Adr);
City = new char[32];
strcpy(City, Ct);
State = new char[30];
strcpy(State, St);
}
//---------------------------------------------------------------------------
Customer::Customer(const Customer &Pers)
: ZIPCode(Pers.ZIPCode)
{
FirstName = new char[strlen(Pers.FirstName) + 1];
strcpy(FirstName, Pers.FirstName);
LastName = new char[strlen(Pers.LastName) + 1];
strcpy(LastName, Pers.LastName);
Address = new char[strlen(Pers.Address) + 1];
strcpy(Address, Pers.Address);
City = new char[strlen(Pers.City) + 1];
strcpy(City, Pers.City);
State = new char[strlen(Pers.State) + 1];
strcpy(State, Pers.State);
}
//---------------------------------------------------------------------------
void Customer::setFirstName(const char *FN)
{
strcpy(FirstName, FN);
}
//---------------------------------------------------------------------------
void Customer::setLastName(const char *LN)
{
strcpy(LastName, LN);
}
//---------------------------------------------------------------------------
void Customer::setAddress(const char *Adr)
{
strcpy(Address, Adr);
}
//---------------------------------------------------------------------------
void Customer::setCity(const char *CT)
{
strcpy(City, CT);
}
//---------------------------------------------------------------------------
void Customer::setState(const char *St)
{
strcpy(State, St);
}
//---------------------------------------------------------------------------
void Customer::setZIPCode(const long ZIP)
{
ZIPCode = ZIP;
}
//---------------------------------------------------------------------------
Customer::~Customer()
{
delete [] FirstName;
delete [] LastName;
delete [] Address;
delete [] City;
delete [] State;
}
//---------------------------------------------------------------------------
code for customer.h
#if !defined CUSTOMER_H
#define CUSTOMER_H
class Customer
{
private:
char* FirstName;
char* LastName;
char* Address;
char* City;
char* State;
long ZIPCode;
public:
void setFirstName(const char *FN);
char* getFirstName() const { return FirstName; }
void setLastName(const char *LN);
char* getLastName() const { return LastName; }
char* FullName() const;
void setAddress(const char *Adr);
char* getAddress() const { return Address; }
void setCity(const char *CT);
char* getCity() const { return City; }
void setState(const char *St);
char* getState() const { return State; }
void setZIPCode(const long ZIP);
long getZIPCode() const { return ZIPCode; }
Customer();
Customer(char *FName, char *LName, char *Adr,
char *Ct, char *St, long ZIP);
Customer(const Customer &Pers);
Customer(char * FName, char * LName);
~Customer();
};
#endif // CUSTOMER_H
code for invoice.cpp
// Invoice.cpp: implementation of the Invoice class.
//
//////////////////////////////////////////////////////////////////////
#include <iostream>
#include <iomanip>
#include <cstring>
#include <cstdlib>
using namespace std;
#include "Invoice.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
Invoice::Invoice()
{
setTankLevel("Empty");
setCarCondition("Good");
}
//--------------------------------------------------------------------
Invoice::~Invoice()
{
}
//--------------------------------------------------------------------
Customer Invoice::CustomerRegistration()
{
char FName[20], LName[20], Addr[40], CT[32], St[30];
long ZC = 0;
cout << "Enter Customer Information\n";
cout << "First Name: "; cin >> FName;
cout << "Last Name: "; cin >> LName;
cout << "Address: "; cin >> ws;
cin.getline(Addr, 40);
cout << "City: ";
cin.getline(CT, 32);
cout << "State: ";
cin.getline(St, 30);
cout << "Zip Code: "; cin >> ZC;
Customer Cust(FName, LName, Addr, CT, St, ZC);
return Cust;
}
//--------------------------------------------------------------------
Car Invoice::CarSelection()
{
int CarType, ModelChosen;
char strCarSelected[20];
int CarSelectedYear = 2000;
cout << "What type of car would you like to rent?";
do {
cout << "\n1 - Economy | 2 - Compact | 3 - Standard"
<< "\n4 - Full Size | 5 - Mini Van | 6 - Sports Utility";
cout << "\nYour Choice: ";
cin >> CarType;
if( CarType < 1 || CarType > 6 )
cout << "\nPlease type a number between 1 and 6";
} while(CarType < 1 || CarType > 6);
switch(CarType)
{
case ctEconomy:
cout << "\nFor the Economy type, we have:"
<< "\n1 - Daewoo Lanos | 2 - Cheverolet Metro";
cout << "\nWhich one would you prefer? ";
cin >> ModelChosen;
if(ModelChosen == 1)
{
strcpy(strCarSelected, "Daewoo Lanos");
CarSelectedYear = 1999;
}
else
{
strcpy(strCarSelected, "Chevrolet Metro");
CarSelectedYear = 1998;
}
break;
case ctCompact:
cout << "\nFor the Compact type, we have:"
<< "\n1 - Chevrolet Cavalier | 2 - Dogde Neon"
<< "\n3 - Nissan Sentra | 4 - Toyota Corolla";
cout << "\nWhich one would you prefer? ";
cin >> ModelChosen;
if(ModelChosen == 1)
{
strcpy(strCarSelected, "Chevrolet Cavalier");
CarSelectedYear = 1999;
}
else if(ModelChosen == 2)
{
strcpy(strCarSelected, "Dodge Neon");
CarSelectedYear = 2001;
}
else if(ModelChosen == 3)
{
strcpy(strCarSelected, "Nissan Sentra");
CarSelectedYear = 1998;
}
else
{
strcpy(strCarSelected, "Toyota Corrolla");
CarSelectedYear = 2002;
}
break;
case ctStandard:
cout << "\nFor the Standard type, we have:"
<< "\n1 - Chevrolet Monte Carlo | 2 - Toyota Camri";
cout << "\nWhich one would you prefer? ";
cin >> ModelChosen;
if(ModelChosen == 1)
{
strcpy(strCarSelected, "Chevrolet Monte Carlo");
CarSelectedYear = 2000;
}
else
{
strcpy(strCarSelected, "Toyota Camri");
CarSelectedYear = 1998;
}
break;
case ctFullSize:
cout << "\nFor the Full Size type, we have:"
<< "\n1 - Chrysler 300M | 2 - Buick Century | 3 - Infinity I30";
cout << "\nWhich one would you prefer? ";
cin >> ModelChosen;
if(ModelChosen == 1)
{
strcpy(strCarSelected, "Chrysler 300M");
CarSelectedYear = 2000;
}
else if(ModelChosen == 2)
{
strcpy(strCarSelected, "Buick Century");
CarSelectedYear = 1999;
}
else
{
strcpy(strCarSelected, "Infinity I30");
CarSelectedYear = 2003;
}
break;
case ctMiniVan:
cout << "\nFor the Mini-Van type, we have:"
<< "\n1 - Dodge Caravan | 2 - Dodge Caravan"
<< "\n3 - Pontiac Montana | 4 - Pontiac Montana | 5 - Chevrolet Astro Van";
cout << "\nWhich one would you prefer? ";
cin >> ModelChosen;
if(ModelChosen == 1)
{
strcpy(strCarSelected, "Dodge Caravan");
CarSelectedYear = 2001;
}
else if(ModelChosen == 2)
{
strcpy(strCarSelected, "Dodge Caravan");
CarSelectedYear = 2003;
}
else if(ModelChosen == 3)
{
strcpy(strCarSelected, "Pontiac Montana");
CarSelectedYear = 2003;
}
else
{
strcpy(strCarSelected, "Chevrolet Astro Van");
CarSelectedYear = 2000;
}
break;
case ctSUV:
cout << "\nFor the Sport Utility type, we have:"
<< "\n1 - GMC Jimmy | 2 - Jeep Cherokee"
<< "\n3 - Chevrolet Blazer | 4 - Toyota Pathfinder";
cout << "\nWhich one would you prefer? ";
cin >> ModelChosen;
if(ModelChosen == 1)
{
strcpy(strCarSelected, "GMC Jimmy");
CarSelectedYear = 1998;
}
else if(ModelChosen == 2)
{
strcpy(strCarSelected, "Jeep Cherokee");
CarSelectedYear = 2003;
}
else if(ModelChosen == 3)
{
strcpy(strCarSelected, "Chevrolet Blazer");
CarSelectedYear = 2001;
}
else
{
strcpy(strCarSelected, "Toyota Pathfinder");
CarSelectedYear = 2000;
}
break;
}
Car Selected(strCarSelected, CarSelectedYear, CarType);
return Selected;
}
//--------------------------------------------------------------------
void Invoice::setMileage(const long g)
{
Mileage = g;
}
//--------------------------------------------------------------------
long Invoice::getMileage() const
{
return Mileage;
}
//--------------------------------------------------------------------
void Invoice::setTankLevel(const char *v)
{
TankLevel = new char[strlen(v) + 1];
strcpy(TankLevel, v);
}
//--------------------------------------------------------------------
char* Invoice::getTankLevel() const
{
return TankLevel;
}
//--------------------------------------------------------------------
void Invoice::setCarCondition(const char *c)
{
CarCondition = new char[strlen(c) + 1];
strcpy(CarCondition, c);
}
//--------------------------------------------------------------------
char* Invoice::getCarCondition() const
{
return CarCondition;
}
//--------------------------------------------------------------------
void Invoice::ProcessOrder()
{
int NbrOfDays;;
double Rate, TotalPrice;
// Enter Customer Information
Customer Person = CustomerRegistration();
cout << "\nProcess Car Information\n";
Car Driving = CarSelection();
TotalPrice = CalculatePrice(Driving, Rate, NbrOfDays);
CarExamination();
// This function works for both Borland C++ Builder and MSVC
system("cls");
cout << " - Bethesda Car Rental -";
cout << "\n=============================";
CustomerInformation(Person);
cout << "\n------------------------------";
CarSelected(Driving);
cout << setiosflags(ios::fixed) << setprecision(2);
cout << "\n------------------------------";
cout << "\nCar Mileage: " << getMileage();
cout << "\nCondition: " << getCarCondition();
cout << "\nTank Level: " << getTankLevel();
cout << "\n# of Days: " << NbrOfDays;
cout << "\n------------------------------";
cout << "\nRate: $" << Rate;
cout << "\nTotal Price: $" << TotalPrice;
cout << "\n==============================\n";
}
//--------------------------------------------------------------------
void Invoice::CustomerInformation(const Customer& Pers)
{
cout << "\nEmployee Identification";
cout << "\nFull Name: " << Pers.FullName();
cout << "\nAddress: " << Pers.getAddress();
cout << "\nCity: " << Pers.getCity() << ", "
<< Pers.getState() << " " << Pers.getZIPCode();
}
//--------------------------------------------------------------------
void Invoice::CarSelected(const Car& Vehicle)
{
cout << "\nModel: " << Vehicle.getMakeModel();
cout << "\nYear: " << Vehicle.getCarYear();
}
//--------------------------------------------------------------------
double Invoice::CalculatePrice(const Car& Vehicle, double& DayRate,
int &NumberOfDays)
{
// char WeekEndResponse;// Does the customer rent the car for the week-end?
double OneDayRate, // If renting for less than 5 days including week-end
WeekDay, // If renting for at least 5 days, regardless of the days
WeekEnd = 0;// If renting for more than two days from Friday to monday
//double DayRate; // Rate applied based on the number of days
double TotalRate;
switch(Vehicle.getCategory())
{
case ctEconomy:
DayRate = 24.95;
OneDayRate = 29.95;
WeekDay = 24.95;
WeekEnd = 19.95;
break;
case ctCompact:
DayRate = 34.95;
OneDayRate = 39.95;
WeekDay = 34.95;
WeekEnd = 25.95;
break;
case ctStandard:
DayRate = 38.95;
OneDayRate = 49.95;
WeekDay = 38.95;
WeekEnd = 32.95;
break;
case ctFullSize:
DayRate = 44.95;
OneDayRate = 69.95;
WeekDay = 44.95;
WeekEnd = 35.95;
break;
case ctMiniVan:
DayRate = 54.95;
OneDayRate = 89.95;
WeekDay = 54.95;
WeekEnd = 42.95;
break;
case ctSUV:
DayRate = 64.95;
OneDayRate = 89.95;
WeekDay = 64.95;
WeekEnd = 50.95;
break;
}
cout << "\nHow many days? "; cin >> NumberOfDays;
TotalRate = DayRate * NumberOfDays;
return TotalRate;
}
//--------------------------------------------------------------------
void Invoice::CarExamination()
{
char Cond;
int GasLevel;
cout << "Rate the car's condition (e=Excellent/g=Good/d=Driveable): ";
cin >> Cond;
if( Cond == 'e' || Cond == 'E' )
strcpy(CarCondition, "Excellent");
else if( Cond == 'g' || Cond == 'G' )
strcpy(CarCondition, "Good");
else if( Cond == 'd' || Cond == 'D' )
strcpy(CarCondition, "Driveable");
else
strcpy(CarCondition, "Can't Decide");
cout << "Enter the car mileage: ";
cin >> Mileage;
do {
cout << "Gas level in the tank"
<< "\n1 - Considered Empty"
<< "\n2 - 1/4 Full"
<< "\n3 - Half Full"
<< "\n4 - 3/4 Full"
<< "\n5 - Full Tank";
cout << "\nEnter the gas level: ";
cin >> GasLevel;
}while(GasLevel < 1 || GasLevel > 5);
switch(GasLevel)
{
case 1:
setTankLevel("Empty");
break;
case 2:
setTankLevel("1/4 Full");
break;
case 3:
setTankLevel("Half Full");
break;
case 4:
setTankLevel("3/4 Full");
break;
case 5:
setTankLevel("Full Tank");
break;
}
}
//--------------------------------------------------------------------
code for invoice.h
#if !defined INVOICE_H
#define INVOICE_H
#include "Customer.h"
#include "Car.h"
#include "RentDate.h"
class Invoice
{
public:
Invoice();
virtual ~Invoice();
Customer CustomerRegistration();
void CustomerInformation(const Customer& Pers);
Car CarSelection();
void CarSelected(const Car& Vehicle);
double CalculatePrice(const Car& Vehicle, double& Rate, int &Days);
void setMileage(const long g);
long getMileage() const;
void setTankLevel(const char *v);
char* getTankLevel() const;
void setCarCondition(const char *c);
char* getCarCondition() const;
void ProcessOrder();
void CarExamination();
void ShowOrder();
private:
long Mileage;
char *TankLevel;
char *CarCondition;
};
#endif // INVOICE_H
code for rentdate.cpp
// RentDate.cpp: implementation of the CRentDate class.
//
//////////////////////////////////////////////////////////////////////
#include <iostream>
#include "RentDate.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CRentDate::CRentDate()
: Month(1), Day(1), Year(1990)
{
}
//---------------------------------------------------------------------
CRentDate::CRentDate(int m, int d, int y)
: Month(m), Day(d), Year(y)
{
}
//---------------------------------------------------------------------
CRentDate::CRentDate(const CRentDate& d)
{
Month = d.Month;
Day = d.Day;
Year = d.Year;
}
//---------------------------------------------------------------------
CRentDate::~CRentDate()
{
}
//---------------------------------------------------------------------
void CRentDate::setDate(int m, int d, int y)
{
Month = m;
Day = d;
Year = y;
}
//---------------------------------------------------------------------
int CRentDate::getMonth()
{
return Month;
}
//---------------------------------------------------------------------
int CRentDate::getDay()
{
return Day;
}
//---------------------------------------------------------------------
int CRentDate::getYear()
{
return Year;
}
//---------------------------------------------------------------------
code for rentdate.h
class CRentDate
{
public:
CRentDate();
CRentDate(int m, int d, int y);
CRentDate(const CRentDate& d);
void setDate(int m, int d, int y);
int getMonth();
int getDay();
int getYear();
virtual ~CRentDate();
private:
int Month;
int Day;
int Year;
};
Sorry about the long reply, i have all the source code. Advance thanks
#7
Re: Error: 'CInvoice' was not declare in this scope
Posted 30 December 2012 - 05:46 AM
So...uh...where is this class you're trying to use called CInvoice?
#8
Re: Error: 'CInvoice' was not declare in this scope
Posted 30 December 2012 - 06:19 AM
#9
Re: Error: 'CInvoice' was not declare in this scope
Posted 30 December 2012 - 06:55 AM
#10
Re: Error: 'CInvoice' was not declare in this scope
Posted 30 December 2012 - 07:04 AM
#11
Re: Error: 'CInvoice' was not declare in this scope
Posted 30 December 2012 - 07:28 AM
So, is it safe to say you copied this code from somewhere?
#12
Re: Error: 'CInvoice' was not declare in this scope
Posted 30 December 2012 - 07:35 AM
Yup.
#13
Re: Error: 'CInvoice' was not declare in this scope
Posted 30 December 2012 - 08:26 AM
Ok, I have already overcome that problem. And now im having problem saying that
"undefined reference to Invoice::Invoice();"
Please help me. Im not very good in programming, I'm trying to learn.
"undefined reference to Invoice::Invoice();"
Please help me. Im not very good in programming, I'm trying to learn.
#14
Re: Error: 'CInvoice' was not declare in this scope
Posted 30 December 2012 - 08:33 AM
Quote
Please help me. Im not very good in programming, I'm trying to learn.
Then I suggest you write your own program from the beginning. Copying code from someone else will not help you learn. You learn programming by programming, not by copying.
Jim
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote




|