d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Issue With Add > Hopefully A Simple Fix
Add Reply New Topic New Poll
Member
Posts: 5,962
Joined: Jul 18 2007
Gold: 615.00
Sep 17 2012 08:07pm
My issue is with the Add function.

The error I receive when I try to compile is:
assignment7.cpp: In function âint main()â:
assignment7.cpp:229: error: âNewPrinterâ was not declared in this scope

If anyone can help me with this I will give the rest of my fg (although it isn't much)

Thanks.


main() in this program would perform these operations:
- Load the first list from the first data file
- Load the second list from the second data file
- Display the first list
- Display the second list
- Print the first list
- Print the second list
- Sort the first list
- Display the first list
- Display the second list
- Print the first list
- Add a new printer to the second list
- Print the second list
- Save the first list to a new data file
- Save the second list to a new data file
- Print the two new data files.

Below is the portions of my code that should be relevant:
#include <iostream>
#include <iomanip>
#include <cstring>
#include <fstream>

using namespace std;

//Declare constants and datatype
const int MODELSIZE=15;
typedef char Model_t[MODELSIZE];
typedef double Cost_t;
const int FILENAMESIZE=80;
typedef char FName_t[FILENAMESIZE];
typedef fstream DataFile_t;
typedef fstream ReportFile_t;

//Printer Entity class
class cPrinter
{
private:
Model_t Model;
Cost_t Cost;
public:
cPrinter();
void KBDInput(DataFile_t & DataFile);
void Display();
void Read(DataFile_t & DataFile);
void Write(DataFile_t & DataFile);
void Print(ReportFile_t & ReportFile);
int CompareTo(cPrinter AnotherPrinter);
};

//Printer List class
class cPrinterList
{
private:
static const int MAXSIZE=20;
cPrinter Printer[MAXSIZE];
cPrinter NewPrinter[MAXSIZE];
int N;
public:
cPrinterList();
void Load();
void Save();
void Display();
void Print();
void Add(cPrinter NewPrinter);
void Sort();
void Swap(cPrinter & Printer1, cPrinter & Printer2);
};



//cPrinterList Add
void cPrinterList::Add(cPrinter NewPrinter)
{
if (N<MAXSIZE)
{
Printer[N] = NewPrinter;
N = N + 1;
}
else
{
}//end if
}//End Add




//Main

main()
{
cPrinterList BuildingA;
cPrinterList BuildingB;
BuildingA.Load();
BuildingB.Load();
BuildingA.Display();
BuildingB.Display();
BuildingA.Print();
BuildingB.Print();
BuildingA.Sort();
BuildingA.Display();
BuildingB.Display();
BuildingA.Print();
BuildingB.Add(NewPrinter);
BuildingB.Print();
BuildingA.Save();
BuildingB.Save();
BuildingA.Print();
BuildingB.Print();
}

This post was edited by UMZeRo on Sep 17 2012 08:08pm
Member
Posts: 114
Joined: Sep 5 2012
Gold: 0.00
Sep 18 2012 12:48pm
Please use code tags, it makes readability a lot better on the eye.

As for the error, assignment7.cpp:229: error: âNewPrinterâ was not declared in this scope

You need to declare a new cPrinter object named NewPrinter
Code
//cPrinter NewPrinter


And you're getting the error, assignment7.cpp: In function âint main()â because you need to return 0 at the end of the function.

Code
int main()
{

return 0;
}
etc



This post was edited by CppDevr on Sep 18 2012 12:50pm
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll