Thread: Project help
View Single Post
Old 11-14-2004, 10:50 PM   #1 (permalink)
verdell32
Registered User
 
verdell32's Avatar
 
Join Date: Oct 2004
Posts: 35
verdell32 is on a distinguished road
Project help

This is the spec's for this project Acme Lumber Company wants a program that will store the SPECIES of wood they sell and the price that they sell it for into to a text file called HARDWOOD.TXT.

Write a program that prompts the user for the name of a type of wood, and the current selling price for the wood. The program will then write the specified information into the HARDWOOD.TXT file, replacing the existing file.
The format of the file called “HARDWOOD.TXT” is:

SPECIES,PRICE

Where SPECIES is the name of the wood. For example: OAK
and PRICE is the price of the wood per board foot. For example: 2.43


Code:
// This program will prompt the user for the name of a type of wood,
// and will output the current selling price for the wood.  
///////////////////////////////////////////////////////////////////////////////

// Include Files //////////////////////////////////////////////////////////////
#include <fstream.h>
#include <iostream.h>
#include <iomanip.h>
#include <conio.h>

// Function Prototypes ////////////////////////////////////////////////////////

// Program Mainline ///////////////////////////////////////////////////////////

int main( )
{
   char specis[64];
   double price;

   //Get data from user
   cout << "Enter hardwood name:" << endl;
   cin.getline( hardwood, sizeof( hardwood ) );
   cin >>
 
   //read data from file
   ifstream fin( "hardwood.txt" );

   ofstream fout("hardwood.txt")

   if (fin,fail) {
      fout << "File " << "hardwood.txt" << " not found!";
      getch();
      return 1;
   }//endif

    getch();
    return 1;
    }//endmn

   fout << hardwood << "\t" << price << "Above data written to        "hardwood.txt" << endl;
   fin.getline( hardwood, sizeof( hardwood ), "\t" );
   fin >> hardwood;
   getch();
   return 0;
}//endmn

Last edited by Valmont; 11-15-2004 at 05:58 AM.
verdell32 is offline   Reply With Quote