Click here to Skip to main content
15,890,512 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: VC++ linker error Pin
Hamid_RT18-Feb-07 4:55
Hamid_RT18-Feb-07 4:55 
GeneralRe: VC++ linker error Pin
Jeffrey Walton18-Feb-07 5:44
Jeffrey Walton18-Feb-07 5:44 
GeneralRe: VC++ linker error Pin
cruppstahl18-Feb-07 7:35
cruppstahl18-Feb-07 7:35 
NewsCode Snippets Manager Pin
marvviki18-Feb-07 2:42
marvviki18-Feb-07 2:42 
Questionmemory mapped I/O and private copies Pin
cruppstahl18-Feb-07 2:28
cruppstahl18-Feb-07 2:28 
AnswerRe: memory mapped I/O and private copies Pin
Waldermort18-Feb-07 3:17
Waldermort18-Feb-07 3:17 
GeneralRe: memory mapped I/O and private copies Pin
cruppstahl18-Feb-07 7:23
cruppstahl18-Feb-07 7:23 
QuestionHow to load text file into an array of structures..? [modified] Pin
Software_Specialist18-Feb-07 2:06
Software_Specialist18-Feb-07 2:06 
Hi all
i have created a simple console application calculating quotations for carpet cost. At the moment it ask user for name, lenght of room and do all calculation and produce output giving detail of the cost.

But now i want that details of previous customer quotation records which are held in a file named “quotes.txt” (a file of records qordered by unique uotation reference numbers). At the start of the program, the file will be loaded into an array of structures called “Quotes” in order that new quote records can be appended and the records can be viewed on screen. The updated file will be saved when the program exits.

So i am stucked here, please help me out. Please see the code below and guide me the right way to add the above functionality...

Thanks a lot

void main()
{
float Length=0, Width=0, Area=0, Cost=0, DeliveryCharge=0;
int UnitPrice=0, GuaranteePeriod=0, DelDistance=0, QuoteNum=INITIAL_QUOTE_REF_NUM;
char AnotherQuote, DelRequired;
char Name[NAME_LEN];
bool ValidPrice;
fstream InputFile;

do
{
//clrscr();

cout << "\nPlease enter surname and initials: ";
cin >> ws;
cin.getline(Name,NAME_LEN);

cout << "Please enter length of room: ";
cin >> Length;

cout << "Please enter width of room: ";
cin >> Width;

do
{
DeliveryCharge=0;
ValidPrice = true;

cout << "Please enter the price per square metre from the following price range:\n\n";
cout << POUND_SIGN << QUALITY_1 << ", " << POUND_SIGN << QUALITY_2 << ", " << POUND_SIGN
<< QUALITY_3 << ", " << POUND_SIGN << QUALITY_4 << ", " << POUND_SIGN << QUALITY_5 << "\n\n" << POUND_SIGN;
cin >> UnitPrice;

cout << "\n\n";

//Assign correct guarantee period for unit price entered.
switch(UnitPrice)
{
case QUALITY_1 : GuaranteePeriod=GUARANTEE_Q1; break;
case QUALITY_2 : GuaranteePeriod=GUARANTEE_Q2; break;
case QUALITY_3 : GuaranteePeriod=GUARANTEE_Q3; break;
case QUALITY_4 : GuaranteePeriod=GUARANTEE_Q4; break;
case QUALITY_5 : GuaranteePeriod=GUARANTEE_Q5; break;
default : cout << "\n\nInvalid price.\n\n";
ValidPrice = false;
}

}while (!ValidPrice);


Area = Length * Width;
Cost = Area * UnitPrice;

cout << "Do you require delivery? (Y/N) ";
cin >> DelRequired;

//Force correct input to delivery question.
while(toupper(DelRequired)!='Y' && toupper(DelRequired)!='N')
{
cout << "Invalid character - enter Y or N:";
cin >> DelRequired;
}

if(toupper(DelRequired)=='Y')
{
cout << "\n\nPlease enter delivery distance in miles: ";
cin >> DelDistance;

if(DelDistance >=0 && DelDistance <=ZONE1)
{
DeliveryCharge = Cost * ZONE1_CHARGE;
}
else
{
if(DelDistance <=ZONE2)
{
DeliveryCharge = Cost * ZONE2_CHARGE;
}
else
{
if(DelDistance <=ZONE3)
{
DeliveryCharge = Cost * ZONE3_CHARGE;
}
else
{
DeliveryCharge = Cost * ZONE4_CHARGE;
}
} //end else > ZONE2
} //end else > ZONE1
} //end delivery required

cout << endl << endl << endl
<< setfill('_') << setw(TABLE_WIDTH) << "" << "\n\n"
<< setfill(' ')
<< setw(7) << " Ref | " << setw(NAME_COL_WIDTH) << " Name | " << setw(COST_COL_WIDTH) << "Carpet | " << setw(DELIVERY_COL_WIDTH)
<< "Delivery | " << setw(TOTAL_COL_WIDTH) << " Total | " << setw(GUARANTEE_COL_WIDTH+7) << "Guarantee |" << endl
<< setfill('_') << setw(TABLE_WIDTH) << "" << "\n\n" << setfill(' ');

cout << fixed << showpoint << setprecision(2);

cout << setfill(' ')
<< setw(7) << QuoteNum << " | "
<< setw(NAME_COL_WIDTH) << Name << " | "
<< setw(1) << POUND_SIGN << setw(COST_COL_WIDTH-4) << Cost << " | "
<< setw(1) << POUND_SIGN << setw(DELIVERY_COL_WIDTH-4) << DeliveryCharge << " | "
<< setw(1) << POUND_SIGN << setw(TOTAL_COL_WIDTH-1) << Cost + DeliveryCharge << " | "
<< setw(7) << "Years: " << setw(GUARANTEE_COL_WIDTH) << GuaranteePeriod << " |"
<< endl;

cout << "\n\nEnter another quote?";
cin >> AnotherQuote;

} while(AnotherQuote=='Y'||AnotherQuote=='y');
///THIS IS WHAT I TRIED, BUT ITS NOT READING THE FILE.........////
/*char FileString[512];

InputFile.open("\\Quotes\\CarpetQuotes.txt", ios::in);
if(InputFile.is_open())
{
InputFile.getline(FileString, sizeof(FileString));
}
*/
cout << "\n" << endl;
system("pause");
}






-- modified at 8:12 Sunday 18th February, 2007
AnswerRe: How to load text file into an array of structures..? Pin
Waldermort18-Feb-07 3:11
Waldermort18-Feb-07 3:11 
GeneralRe: How to load text file into an array of structures..? Pin
Software_Specialist18-Feb-07 4:36
Software_Specialist18-Feb-07 4:36 
GeneralRe: How to load text file into an array of structures..? Pin
Waldermort18-Feb-07 5:11
Waldermort18-Feb-07 5:11 
GeneralRe: How to load text file into an array of structures..? Pin
David Crow18-Feb-07 16:29
David Crow18-Feb-07 16:29 
GeneralRe: How to load text file into an array of structures..? Pin
Waldermort18-Feb-07 18:24
Waldermort18-Feb-07 18:24 
GeneralRe: How to load text file into an array of structures..? Pin
Software_Specialist19-Feb-07 1:53
Software_Specialist19-Feb-07 1:53 
AnswerRe: How to load text file into an array of structures..? Pin
Bram van Kampen19-Feb-07 13:30
Bram van Kampen19-Feb-07 13:30 
Questiondispaly thambnails of the images on the view Pin
vasu_sri18-Feb-07 0:33
vasu_sri18-Feb-07 0:33 
AnswerRe: dispaly thambnails of the images on the view Pin
Hamid_RT18-Feb-07 4:41
Hamid_RT18-Feb-07 4:41 
QuestionRe: dispaly thambnails of the images on the view Pin
Mark Salsbery18-Feb-07 7:19
Mark Salsbery18-Feb-07 7:19 
QuestionResource Localization (Polish Character) Pin
Anik3318-Feb-07 0:28
Anik3318-Feb-07 0:28 
AnswerRe: Resource Localization (Polish Character) Pin
ovidiucucu18-Feb-07 12:38
ovidiucucu18-Feb-07 12:38 
Questiondisplaying the thumbnail preview of the images on the view Pin
vasu_sri17-Feb-07 22:05
vasu_sri17-Feb-07 22:05 
AnswerRe: displaying the thumbnail preview of the images on the view Pin
Hamid_RT18-Feb-07 4:40
Hamid_RT18-Feb-07 4:40 
GeneralRe: displaying the thumbnail preview of the images on the view Pin
vasu_sri18-Feb-07 19:45
vasu_sri18-Feb-07 19:45 
GeneralRe: displaying the thumbnail preview of the images on the view Pin
Hamid_RT18-Feb-07 20:40
Hamid_RT18-Feb-07 20:40 
GeneralRe: displaying the thumbnail preview of the images on the view Pin
vasu_sri19-Feb-07 22:30
vasu_sri19-Feb-07 22:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.