Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 11-22-2004, 11:59 AM   #1 (permalink)
verdell32
Registered User
 
verdell32's Avatar
 
Join Date: Oct 2004
Posts: 35
verdell32 is on a distinguished road
hardwood Program help

I have already done the first part of the program called setprice; now I am working on the hardwood.cpp and in order to do this I had to know what a "boardfoot" is and this is how I am suppossed to come up with the calculations.
But I am stuck on this point. Could some one look over my code and see if I am doing it correctly?

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

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

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

int main( )
{
   char woodName[64];
   double price;
   int boardfoot;
   int thickness;
   int width;
   int length;

   //Get data from user
   cout << "Enter hardwood name: " ;
   cin.getline( woodName, sizeof( woodName ) );
   cout << "Enter price of wood: " ;
   cin >> price;
   cout<< "Enter thickness:";
   cin >> thickness;
   cout << "Enter width:";
   cin >> width
   cout <<"Enter length:";
   cin >> length;

   //read data from file
   ofstream fout( "HARDWOOD.TXT" );

   //Calculations
   boardfoot = (thickness * width * length) /12;
   getPrice = don't know how to calculate once the person inputs the price for the oak 2.43,red oak 3.45,walnut 4.43,birch 1.99?
   

   if (fout.fail() ) {
      cout << "Could not open file." <<endl;
      getch();
      return 1;
   }//endif

   fout << woodName <<",\t"<< price << endl;
   cout << woodName <<",\t"<< price << endl;
   cout << "Above data written to file HARDWOOD.TXT" << endl;
   cout << woodName <<"\t"<<boardfoot<<enl;
   cout << getPrice << "\t"<< getPrice<<endl;
   getch();
   return 0;
   }//endmn

Last edited by Valmont; 11-22-2004 at 12:45 PM.
verdell32 is offline   Reply With Quote
Old 11-22-2004, 12:58 PM   #2 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
Give me the rest of the code. I want to see setPrice and everything else you've got.
For now, I can only gamble a bit about your exact intentions. Besides, you are mixing C with C++. I'll take the liberty of re-creating your code the proper way once I have the rest.
__________________
Valmont is offline   Reply With Quote
Old 11-23-2004, 11:51 AM   #3 (permalink)
verdell32
Registered User
 
verdell32's Avatar
 
Join Date: Oct 2004
Posts: 35
verdell32 is on a distinguished road
Code for Setprice

This is the first part of the code and this works fine; it has already created the "hardwood file" that will hold the values for the Wood that a person would enter in. So what the program will do in the hardwood is : the cashier will enter in the Thickness, Width, Length and that will output the "Boardfoot" and the price will also be input and it will output the price that the person inputs. So I think that the price that is input will be multiplied by the measurements; and that should give you the totalprice; and the totalprice should print out on a ticket(Reciept). I hope I explained this well.
Thanks Valmont



Code:
// Program Documentation //////////////////////////////////////////////////////
//
// Project Name  : SETPRICE
//
// Source File   : setprice.cpp
//
// Programmed By : Shang Fields
//
// Last Revision : 11/8/2004
//
// Version Number: 0.1
//
// Program Description ////////////////////////////////////////////////////////
//
// 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 woodName[64];
   double price;

   //Get data from user
   cout << "Enter hardwood name: " ;
   cin.getline( woodName, sizeof( woodName ) );
   cout << "Enter price of wood: " ;
   cin >> price;
   //read data from file
   ofstream fout( "HARDWOOD.TXT" );

   if (fout.fail() ) {
      cout << "Could not open file." <<endl;
      getch();
      return 1;
   }//endif

   fout << woodName <<",\t"<< price << endl;
   cout << woodName <<",\t"<< price << endl;
   cout << "Above data written to file HARDWOOD.TXT" << endl;
   getch();
   return 0;
}//endmn

Last edited by Valmont; 11-23-2004 at 04:42 PM.
verdell32 is offline   Reply With Quote
Old 11-23-2004, 05:29 PM   #4 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
You are only guessing on how to calculate the prices, so the only thing I can do is guessing too. That I won't do. My credo stands:

Programming is communicating.

So that part I cannot do. You will need to ask your teacher how he interpretes the final price of the wood type. He is also responsible for defining "boardfoot".
I'll explain:
One of my first jobs long ago was junior coder at CMG Netherlands. That's a biggie, trust me on that. The job was simple: learn this book (telecommunication) and start coding.
I had no questions anymore. If I needed to know what is what, I learn the book at evening. And the next day I add another ten lines of code. Because I had the means of understanding telecom, I could move on.

Now, how can I or you know about the world of wood, if no one tought you or me.

As for your code, here is an improvement in standard (ISO) C++. It the *.txt file already exists, then new entries are ADDED to the file. run the program a few times then open hardwood.txt and see what's in it.
Code:
#include <iostream>
#include <string>
#include <climits>
#include <fstream>

using std::cin;
using std::cout;
using std::endl;
using std::numeric_limits;
using std::streamsize;
using std::ofstream;
using std::string;
using std::getline;
using std::ios;

//Optional function: depends on IDE. Remove in final release.
void wait_for_enter();

int main(int argc, char *argv[])
{
   string woodName;
   double price;

   //Get data from user
   cout << "Enter hardwood name: " ;
   getline(cin, woodName);
   
   cout << "Enter price of wood: " ;
   cin >> price;
   
   //Open file for writing. We add the wood types and prices to the file.
   ofstream fout( "HARDWOOD.TXT",  ios::app );
   if ( fout ) //<-- file has been opened or created successfully.
   {
      fout << woodName <<'\t' << price << endl;
      fout.close();
      if( !fout.fail() )
      {
         cout << "Above data written to file HARDWOOD.TXT" << endl;
      }
      else
      {
         cout << "ERROR: something has gone wrong during writing of file."<<endl;
      }
      cout << woodName <<",\t" << price << endl;
   }
   else // <-- file could not be opened or created for some reason.
   {
      cout << "ERROR: could not open or create file." << endl;
      cout << "NOTICE: all processes have been skipped." << endl;
   }
   
   //Remove this for release version.
   cin.ignore(numeric_limits<streamsize>::max(), '\n');
   wait_for_enter();
   return 0;

}

//---------------------------------------------------

void wait_for_enter()
{
  cout << "press <enter> to continue...";
  // Reset failstate, just in case.
  cin.clear();
  string line;
  getline( cin, line);
}
Quote:
I hope I explained this well.
No, but that is not your fault. No one tought you yet.
Because of the simplicity, the model was clear to me: I think I know what you are talking about.
But I don't know what the requirements EXACTLY are for the application TO DO. So I gamble a bit and decide to append new entries to the file.
This is called "use case": what does it do, what is it exactly responsible for.
__________________
Valmont is offline   Reply With Quote
Old 11-24-2004, 01:55 PM   #5 (permalink)
verdell32
Registered User
 
verdell32's Avatar
 
Join Date: Oct 2004
Posts: 35
verdell32 is on a distinguished road
Thumbs up Thanks again

I think this is pretty close to the program; the only thing in Borland C++ 5 it doesn't recognize <climits>.
verdell32 is offline   Reply With Quote
Old 11-24-2004, 08:23 PM   #6 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
try limits.h
__________________
Valmont is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
simple question 'bout compiling c program if13121 Platform/API C++ 0 11-09-2004 10:36 PM
C++ Deadlock Detection Program Help... coolsc81 Standard C, C++ 2 10-26-2004 06:14 AM
Help on starting new program B00tleg Standard C, C++ 21 10-17-2004 12:58 PM
Help on interest program B00tleg Standard C, C++ 2 10-07-2004 08:50 PM


All times are GMT -8. The time now is 06:30 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting