I am having trouble with program that reads inventory information and outputs a .txt file though a gui.

I am having an problem where the in information is either being read but not outputting to the .txt file or not being read correctly and is not outputting the data to the .txt file. http://imgur.com/a/4Eyk5 <- images for information on the project. Please help me out as I have been working on this for hours and can't find the issue.

***Floppy.h****

void ListRecords ( char * );

void InsertItem( int, int, double, double, char [], int, Floppy*);

int CountItems( );

// Return the value of the private members
// By adding the "const" modifier the function prevented from modifying data in the class
int GetProIdIn() const;
int GetManIdIn() const;
double GetWhoPrIn() const;
double GetMarkUpIn() const;
char* GetDescrIn() const;
int GetQuanInStockIn() const;
Floppy*GetLink() const;


//Retail Price Function
double GetRePrice() const;

//set the values of the private members

void SetProIdIn ( int );
void SetManIdIn ( int );
void SetWhoPrIn ( double) ;
void SetMarkUpIn ( double) ;
void SetDescrIn ( char [ ] );
void SetQuanInStockIn ( int );
void SetLink ( Floppy* );

private:
int ProIdIn;
int ManIdIn;
double WhoPrIn;
double MarkUpIn;
//"mutable" is to specify which data members can be modified by const member functions
mutable char DescrIn[35];
int QuanInStockIn;
Floppy*NextRecordPointer;
};
#endif


***form1.h(gui code) for the report and exit button plus the text box.***

private: System::Void HeadingTextBox_Click(System::Object^ sender, System::EventArgs^ e) {

HeadingTextBox->Clear();

}
private: System::Void HeadingTextBox_TextChanged(System::Object^ sender, System::EventArgs^ e) {


}
private: System::Void ExitButton_Click(System::Object^ sender, System::EventArgs^ e) {

//This will exit the program
Application::Exit();

}
private: System::Void ReportButton_Click(System::Object^ sender, System::EventArgs^ e) {


Floppy* CurrentRecordPointer;
ifstream DataFile;
int InitProIdIn = 0;
int InitManIdIn = 0;
double IntiWhoPrIn = 0.0;
double InitMarkUpIn = 0.0;
char InitDescrIn[35] = "\0";
int InitQuanInStockIn = 0;
char* ReportName;

DataFile.open((char*)(void*) Marshal::StringToHGlobalAnsi
(String::Concat(Directory::GetCurrentDirectory(),
"\\ProductFileForInput.txt")));

if (!DataFile)
{
Application::Exit();
return;
}

//Read input file
DataFile >> InitProIdIn;
DataFile.ignore();
DataFile >>IntiWhoPrIn;
DataFile >> InitMarkUpIn;
DataFile.get (InitDescrIn, 31);
DataFile>>InitQuanInStockIn;



while(DataFile)
{
CurrentRecordPointer = new Floppy;

CurrentRecordPointer->InsertItem(InitProIdIn, InitManIdIn, IntiWhoPrIn, InitMarkUpIn, InitDescrIn, InitQuanInStockIn, CurrentRecordPointer);
DataFile >> InitProIdIn;
DataFile.ignore();
DataFile >>IntiWhoPrIn;
DataFile >> InitMarkUpIn;
DataFile.get (InitDescrIn, 31);
DataFile>>InitQuanInStockIn;


}
//Get Report name entered and put in ReportName Text Box

ReportName = (char*)(void*)Marshal::StringToHGlobalAnsi
(HeadingTextBox->Text);

FirstRecordPointer->ListRecords(ReportName);

HeadingTextBox->Clear();
HeadingTextBox->Text = "Output File Created";

delete CurrentRecordPointer;
FirstRecordPointer=NULL;
DataFile.close();
}
};
}



***Floppy.cpp***
#include "stdafx.h"
//#include "Floppy.h"

Floppy * FirstRecordPointer;

//Constructors

Floppy::Floppy()
{
ProIdIn = 0;
ManIdIn = 0;
WhoPrIn = 0;
MarkUpIn = 0;
DescrIn [34] = '\0';
QuanInStockIn = 0;
NextRecordPointer = NULL;
}


void Floppy::ListRecords( char * ReportName )
{
ofstream OutputFile;
Floppy * CurrentRecordPointer;
char Separator[60] = "____________________________________________________";

OutputFile.open((char*)(void*)Marshal::StringToHGlobalAnsi(String::Concat(Directory::GetCurrentDirectory(),
"\\ProductFileForOutput.txt")));

if (!OutputFile)
{
Application::Exit( );
return;
}

OutputFile << endl << Separator << endl << endl;
OutputFile << setw(38) << setfill(' ') << ReportName << setw(30) << setfill(' ')<<"Page # 1"<<endl;
OutputFile << Separator;
OutputFile << endl << endl << setw(15) << setfill(' ') << "Product"
<< setw(16) << setfill(' ') << "Product"
<< setw(19) << setfill(' ') << "Manufacturer's"
<< setw(19) << setfill(' ') << "Retail"
<< setw(19) << setfill(' ') << "Quantity"<< endl
<< setw(11) << setfill(' ') << "Number"
<< setw(21) << setfill(' ') << "Description"
<< setw(21) << setfill(' ') << "Id Number"
<< setw(21) << setfill(' ') << "Price"
<< endl << Separator << endl << Separator << endl;


CurrentRecordPointer = FirstRecordPointer;
while( CurrentRecordPointer != NULL )
{
OutputFile << endl;
OutputFile << right;
OutputFile << endl << CurrentRecordPointer->GetProIdIn();

OutputFile << CurrentRecordPointer->GetDescrIn();

OutputFile << CurrentRecordPointer->GetManIdIn();

OutputFile<< fixed << " $ " << CurrentRecordPointer->GetRePrice();

OutputFile << CurrentRecordPointer->GetQuanInStockIn();

CurrentRecordPointer = CurrentRecordPointer->GetLink( );
}

OutputFile << endl << Separator << endl;

OutputFile.close( );
return;
}

// * Add an item to the head of the linked list *

void Floppy::InsertItem( int InitProIdIn, int InitManIdIn, double InitWhoPrIn, double InitMarkUpIn, char InitDescrIn[], int initQuanInStockIn, Floppy* CurrentRecordPointer )
{
Floppy* CurrentPointer; // Pointer to traverse the list
Floppy* TrailPointer; // Pointer to previous record
bool Found;

ProIdIn = InitProIdIn;
ManIdIn = InitManIdIn;
WhoPrIn = InitWhoPrIn;
MarkUpIn = InitMarkUpIn;
strcpy_s( DescrIn, InitDescrIn );
QuanInStockIn = initQuanInStockIn;


if( FirstRecordPointer == NULL )
{
FirstRecordPointer = CurrentRecordPointer;
}
else
{
CurrentPointer = FirstRecordPointer;
Found = false;

// * Search the linked list *

while( CurrentPointer != NULL && !Found )
{
if( CurrentPointer->ProIdIn >= InitProIdIn )
{
Found = true;
}
else
{
TrailPointer = CurrentPointer;
CurrentPointer = CurrentPointer->GetLink( );
}
}

if( CurrentPointer == FirstRecordPointer )
{
NextRecordPointer = FirstRecordPointer;
FirstRecordPointer = CurrentRecordPointer;
}
else
{
TrailPointer->NextRecordPointer = CurrentRecordPointer;
NextRecordPointer = CurrentPointer;
}
}
}

int Floppy::CountItems()
{
Floppy* CurrentRecordPointer;
int ItemCounter = 0;

for( CurrentRecordPointer = FirstRecordPointer;
CurrentRecordPointer != NULL;
CurrentRecordPointer = CurrentRecordPointer->GetLink())
{
ItemCounter++;
}
return (ItemCounter);
}




// Return the value of the private class members
int Floppy:: GetProIdIn( ) const
{
return ( ProIdIn );
}

int Floppy:: GetManIdIn() const
{
return ( ManIdIn);
}

double Floppy::GetWhoPrIn() const
{
return ( WhoPrIn);
}

double Floppy::GetMarkUpIn() const
{
return ( MarkUpIn);
}

char* Floppy::GetDescrIn() const
{
return (DescrIn);
}

int Floppy::GetQuanInStockIn() const
{
return ( QuanInStockIn);
}

Floppy* Floppy::GetLink( ) const
{
return NextRecordPointer;
}

//display info

// * Set the value of the private class members *
// **********************************************
void Floppy::SetProIdIn( int InitProIdIn )
{
ProIdIn = InitProIdIn;
}

void Floppy::SetManIdIn( int InitManIdIn )
{
ManIdIn = InitManIdIn;
}

void Floppy::SetWhoPrIn( double InitWhoPrIn)
{
WhoPrIn = InitWhoPrIn;
}

void Floppy::SetMarkUpIn( double InitMarkUpIn)
{
MarkUpIn = InitMarkUpIn;
}

void Floppy::SetDescrIn( char InitDescrIn[] )
{
strcpy_s( DescrIn, InitDescrIn );
}

void Floppy::SetQuanInStockIn( int InitQuanInStockIn )
{
QuanInStockIn = InitQuanInStockIn;
}

void Floppy::SetLink( Floppy* InitLink )
{
NextRecordPointer = InitLink;
}

double Floppy::GetRePrice() const

{
return (WhoPrIn + ( WhoPrIn*MarkUpIn));
}

I only put in the code that was important and the formatting is not done.
Last edited on
Does this program use cin and cout?
no, what I posted is everything. At least, the bits that is the issue.
Last edited on
No, what I posted is everything. At least, the bits that is the issue.

That is just Floppy.h. Where is the function main() or WinMain()?
Sorry here: //Specification File Floppy.h

#ifndef FLOPPY_H
#define FLOPPY_H

#include <iostream>
#include <fstream>
#include <iomanip>

using namespace std;
using namespace System;
using namespace System::IO;
using namespace System::Windows::Forms;
using namespace System::Runtime::InteropServices;

There isn't any for this program.
The issue is the fact that it isn't reading the information from the text file or not outputting the data to a new text file correctly. There is no red underlined errors. Check the images in the url I posted.
Last edited on
Also the input text file is in the right location. If anyone asks.
Can you upload the whole project somewhere with the input file?
Problems are easier to find when you can use debugger.
I fixed it.

I was missing a datafile entry " DataFile >> InitManIdIn; " and need to move the DataFile.ignore();.

The correct way below:

DataFile >> InitProIdIn;
DataFile >> InitManIdIn;
DataFile >>IntiWhoPrIn;
DataFile >> InitMarkUpIn;
DataFile.ignore();
DataFile.get (InitDescrIn, 31);
DataFile>>InitQuanInStockIn;
Last edited on
Topic archived. No new replies allowed.