Google Answers Logo
View Question
 
Q: C++programming ( No Answer,   0 Comments )
Question  
Subject: C++programming
Category: Computers > Programming
Asked by: integrated-ga
List Price: $70.00
Posted: 05 Feb 2004 15:09 PST
Expires: 07 Feb 2004 05:23 PST
Question ID: 303912
please have a go at compiling this program thats all i want. iam using
a c++borland 5.5


#include<iostream.h>

using std::cout;
using std::cerr;
using std::cin;
using std::endl;
using std::ios;

#include <fstream.h>

using std::ofstream;
using std::ostream;
using std::fstream;

#include <iomanip.h>

using std::setiosflags;
using std::resetiosflags;
using std::setw;
using std::setprecision;

#include <cstdlib>
#include "clntdata.h"

int enterchoice(0;
void textfile ( fstream& );
void updaterecord( fstream& );
void newrecord( fstream& );
void deleterecord( fstream& );
void outline ( ostream&, const clientdata &);
int getaccount9 const char * const );

enum choices { textile =1, update, new, delete, end };

int main()
{
 fstream inoutcredit( "credit.dat", ios::in / ios::out);

 if (!inoutcredit) {
    cerr <<"file could not be opened."<<endl;              
    exit(1);
  }
 int choice;

 while (( choice = enterchoice()) !=end ) {

  switch (choice) {
   case textfile:
    textfile( inoutcredit );
    break;
   case update:
    updaterecord ( inoutcredit );
    break;
   case new:
    newrecord( inoutcredit );
    break;
   case delete:
    deleterecord( inoutcredit );
    break;
  default:
   cerr << "incorrect choice\n";
   break;
  }
  inoutcredit.clear();  // resets end of file indicator

 }
 return 0;

 }
  //prompt for and input menu choice
  int enterchoice()
  {

   cout <<"\nenter your choice " <<endl
	<< "1 - store a formatted text file of accounts\n"
	<< "    called \"print.txt\" for printing\n"
	<< "2 - update an account\n"
	<< "3 - add a new account\n"
	<< "4 - delete an account\n"
	<< "5 - end program\n? ";


   int menuchoice;
   cin >>menuchoice;
   return menuchoice;

  }

  // create formatted text file for printing
  void textfile ( fstream &readfromfile )
   {
     ofstream outprintfile( "print.txt", ios::out );

     if ( !outprintfile ) {
	 cerr << "file could not be opened." <<endl;
	 exit(1);
     }

   outprintfile <, setiosflags( ios::left ) << setw(10)
    << "account" << setw(16) << "last name" <<setw(11)
    << "first name" <, resetiosflags( ios::left)
   readfromfile.seekg(0);

   clientdata client;
   readfromfile.read( reinterpret_cast<char *>( &client),
		     sizeof (clientdata));


  while ( !readfromfile.eof()){
   if(client.accountnumber !=0)
   outputline(outprintfile, client );

   readfromfile.read (reinterpret_cas<char *>( &client),
		     sizeof (clientdata));

   }

 }

 //update an account's balance
 void updaterecord ( fstream &updatefile )

 {
  int account = getaccount ( "enter account to update" );

  update file.seekg(( account - 1) * sizeof (clientdata));

  clientdata client;
  updatefile.read (reinterpret_cast<char *>( &client),
		    sizeof( clientdata));

  if (client.accountnumber !=0){
     outputline( cout, client);
     cout<<"nenter charge (+) or payment (-):";

     double transaction ;      //charge or payment
     cin >>transaction;        //should validate
     client.balance +=transaction;
     outputline(cout, client);
     updatefile.seekp((account-1) *sizeof (clientdata));
     updatefile.write(
		      reinterpret_cast<const char *>(&client),
		      sizeof(clientdata));
 }
 else
     cerr<<"account#"<<account
	 <<"has no information."<<endl;

  {

  //create and insert new record
  void newrecord (fstream&insertinfile)

  {
    int account = getaccount ( "enter new account number");
    insertinfile.seekg((account-1) * sizeof(clientdata));

    clientdata client;
    insertinfile.read(reinterpret_cast<char*>(client),
		      sizeof(clientdata));

    if(client.accountnumber == 0) {
      cout<< "enter lastname, firstname, balance\n?";
      cin>>client.lastname >>client.firstname
	 >>clientbalance;
      client.accountnumber =account;
      insertinfile.seekp((account-1)*
      sizeof(clientdata));

      insertinfile.write(
	       reinterpret_cast<const char *>(&client),
	       sizeof(clientdata));

      }
      else
	   cerr<<"account#"<<account
	       <<"already contains information."<<endl;

    }

    //delete an existing record
    void deleterecord( fstream &deletefromfile)

    {
      int account = getaccount ("enter account to delete");

      deletefromfile.seekg((account-1) * sizeof (clientdata));

      clientdata client;
      deletefromfile.read(reinterpret_cast<char *>(&client),
			  sizeof(clientdata));

      if(client.accountnumber !=0) {
      clientdata blankclient={0, "","", 0.0};

	  deletefromfile.seekp((account-1)*
				sizeof(clientdata));

       deletefromfile.write(
	      reinterpret_cast<const char *>( &blankclient ),
	      sizeof(clientdata));
       cout<<"account #" <<account<< "deleted."<<endl;
          
      }
      else
        cerr<<"account#" <<account<< "is empty."<<endl;
 }

 //output a line of client information

 void outputline (ostream &output, const clientdata &c)
 {

  output <<setiosflags(ios::left) <<setw(10)
	 <<c.accountnumber <<setw(16)<< c.lastname
	 <<setw (11)<< c.firstname<<setw(10)
	 <<setprecicsion(2)<<resetiosflags(ios::left)
	 <<c.balance<< '\n';

  }
   // get an account number from thye keyboard
   int getaccount( const char * const prompt)
   {
    int account;

     do{
	cout<<prompt<<"(1-100):";
	cin>>account;
     }while (account 1||account > 100);

      return account;
}

Request for Question Clarification by joseleon-ga on 05 Feb 2004 15:25 PST
Hello, integrated:
  Do you want the resulting executable?

Regards.

Request for Question Clarification by maniac-ga on 05 Feb 2004 16:21 PST
Hello Integrated,

Are you looking for guidance in fixing all the compilation errors?

For example (line #:comment)
 25: replace 0 with )
 33: textfile, new, delete are already defined, try xtextfile, xnew,
xdelete as enumeration values
 37: replace / (divide) with | bitwise inclusive or
 48: replace textfile with xtextfile
 54: replace new with xnew
 57: replace delete with xdelete
 99: replace <, with <<
101: replace <, with <<
and so on for the simple syntax errors. There are a number of other
problems such as undefined variables and so on. Do you need help on
fixing all these or something more comprehensive (e.g., help in
writing some of the other functions)?

Also, you should supply clntdata.h to get a complete answer.
  --Maniac

Clarification of Question by integrated-ga on 05 Feb 2004 16:35 PST
joseleon-ga  yes thats right i need the program to be fully compiled.

maniac-ga yes i do need all the errors fixed > other functions that
needs to be written come later i will let u know

 thanks guys 
               intergrated

Request for Question Clarification by maniac-ga on 05 Feb 2004 18:07 PST
Hello Integrated,

OK. I have a clean compile.

For reference, I created clntdata.h as

struct clientdata { 
  int accountnumber;
  char * lastname;
  char * firstname;
  double balance;
};

It is good enough to get a clean compile, but is obviously not correct
since the program does not work properly (bus error when trying to add
an account).

I ask again - please post a copy of your clntdata.h as a
clarification. I will make sure the code will compile cleanly with
your file. I will also try some basic tests and fix any obvious
problems. I will then post the revised code as the answer and explain
the changes so you can understand the steps I took to get there.

  --Maniac

Clarification of Question by integrated-ga on 06 Feb 2004 03:19 PST
maniac - i have send a program which i have made in pascal and i
wanted to convert it into C++ with the following features that i have
numbered underneath.

a C++ program where a customer can invest in a number of different
account types.withdraw and deposit  money into the account as many as
they wish in a day.

lets say :

friendly welcome screen 
1.) savings account       i only want three types of account    
2.) current account
3.) current plus
--------------------     
3.) withdraw        
4.) deposit           
-----------------------
5.)friendly exit program

PROGRAM BankInt; (*by Shiv Kapoor*)

Uses WinCrt;

Const
  FIVE   = 5;
  SEVEN  = 7;
  TEN    = 10;
  TWELVE = 12;
  Message = 'KTC Banking System';

TYPE
  AccRec = RECORD
             Names   : string[15];
             AcctNo  : string[10];
             AccType : char;
             Amount  : real;
             NewBal  : real;
           END;

  List = Array[1..20] of accRec;

VAR select     : char;
    customers  : List;
    ListEnd    : integer;
    EndMessage : char;
(******************************************************************)


PROCEDURE Keypress;
Begin
  gotoxy(10,25); Write('To continue press ENTER...');
  ReadLn;
End;

(******************************************************************)



PROCEDURE Menu(VAR select : char);
  BEGIN
    ClrScr;
    gotoxy(28,1);WriteLn(Message);
    gotoxy(28,3);WriteLn('Customers Record');
    gotoxy(15,4);WriteLn('==========================================');
    WriteLn('1. Input customers details');
    WriteLn('2. Display accounts details');
    WriteLn('9. EXIT');
    gotoxy(25,10);Write('Select from one of the above options ');
    ReadLn(select);
    END;
(*******************************************************************************************************)

PROCEDURE Calculate(VAR customers:List; VAR ListEnd:integer);
VAR i: integer; {Local Variable}

BEGIN
FOR i :=1 to ListEnd DO
  BEGIN
    WITH Customers[i] DO
    BEGIN
      CASE AccType OF

      'S' : IF Amount < 5000 THEN
               NewBal := Amount + (Amount * TEN/100)
            ELSE
               NewBal := Amount + (Amount * TWELVE/100);
      'C' : IF Amount < 100 THEN
               NewBal := Amount + (Amount * FIVE/100)
            ELSE
               NewBal := Amount + (Amount * SEVEN/100);

      END;
    END;
  END;
END;
(*********************************************************************************************************)

PROCEDURE Input(VAR customers:List; VAR ListEnd:integer);
VAR choice : char; {Local variable}

BEGIN
REPEAT {Repeat until user type 'N'}
   ListEnd:=ListEnd+1;
   WITH Customers[ListEnd] DO
   BEGIN
     WriteLn('Customers Details');
     WriteLn('=================');
     Write('Account holders name =====> ');
     ReadLn(Names);
     Write('Account number ===========> ');
     ReadLn(AcctNo);
     Write('Account type (C or S) ====> ');
     ReadLn(Acctype);
     Write('Amount ===================>£');
     ReadLn(Amount);
   End;

   Repeat
     WriteLn('Enter another customer? (Y/N)');
     ReadLn(choice);
     Until (Choice in ['N','Y']);
   UNTIL Choice ='N'; {Repeat until types 'N'}
   Calculate(Customers, ListEnd);
   END;
(********************************************************************************************************)

PROCEDURE Display(VAR customers:List; VAR ListEnd:integer);
VAR i: integer;
BEGIN
  IF ListEnd > 0 THEN
     BEGIN
       ClrScr;
       gotoxy(25,2);WriteLn('====================');
       gotoxy(25,3);WriteLn('STATEMENT OF ACCOUNT');
       gotoxy(25,4);WriteLn('====================');
       WriteLn;
       WriteLn('Account name':16, 'Acct No.':11, 'A/C Type':10, 'Old
Balance':15, 'New Balance':15);
       WriteLn('------------':16, '--------':11, '--------':10,
'-----------':15, '-----------':15);
       FOR i := 1 TO ListEnd DO
        BEGIN
          WITH Customers[i] DO {change i was ListEnd}
            BEGIN
              WriteLn(Names:16,AcctNo:11,AccType:8,Amount:15:2,NewBal:15:2);
            END; {of WITH}
        END;     {of FOR }
       WriteLn
     END
  ELSE
    BEGIN
       Writeln('No Accounts in the system');
    END;
  Keypress;
END;




(************************************************************************************************************)

BEGIN {of main program}

ListEnd := 0;
    REPEAT
      Menu(select);
      CASE select OF
      '1' : Input (customers, ListEnd);
      '2' : Display(customers, ListEnd);
      END;
      UNTIL select ='9';
      gotoxy(23,25);WriteLn('Thanks for using KTC banking system');
      ReadLn(EndMessage);

END.
(***********************************************************************************

Ps. forget about the program that i have posted yesterday totally have
a crack at this one for me please

Clarification of Question by integrated-ga on 06 Feb 2004 03:21 PST
maniac- i forget to mention that 
5.) display summary reports for all the accounts 
6.)exit program

thanks integrated
Answer  
There is no answer at this time.

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy