0

i have this code to be written in C. i was to make an atm with a unique pin no. required. my prof gave me a copy of the program in c++ and asked me to "convert" it in C. how do you do that? there are so many seperate codes and i dont know how to make them just a simple single program.this are the programs:

Attachments
#include "account.h"

//constructors
account::account ()
//This is the default constructor for accounts and it sets all the values to 0
{
	balance = 0;
}

account::~account ()
//Deconstructor does nothing 
{
}

//modifiers
void account::deposit (const double &amount)
//This function takes an amount and it will be deposited into the account
{
		balance += amount;
}

void account::withdrawal (const double &amount)
//This function takes an amount and it will be withdrawn from the account
{
		balance -= amount;
}

//accessors
double account::inquire ()
//This function returns the balance of the account
{
	return balance;
}

double account::interest ()
//This function adds the intesest per month to the account and prints the new balance out. 
//Precondition: this function won't be run more than once
{
	return balance * INTER_RATE/1200;
}
//Jun Nozaki	10/17/2000	This is the header file for the bank class.
//Holds a balance, you can deposit and withdraw from it
//You can also inquire about the balance and interest earned 

#ifndef _ACCOUNT_H
#define _ACCOUNT_H

#include <iostream.h>

const double INTER_RATE = 2;  //fixed interest rate at 2% APY

class account
{
	public:
		//constructors
		account ();
		~account (); //default destructor

		//modifiers
		void deposit (const double &amount);
		void withdrawal (const double &amount);

		//accessors
		double inquire (); //returns the balance
		double interest (); //returns the interest earned

	private:
		double balance; //holds the balance
};

#endif
// *******************************************************************
//  Revised: January 13, 1998,  <= and >= redefined using ! and <
//                              operator += now takes constant
//                              amortized time for adding one char
//
//  Revised: November 19, 1998, replaced assert with exit: operator[]
//                              changed operator >> and getline
//                              so no limit on size of strings read
//
//  APCS string class  IMPLEMENTATION
//
//  see apstring.h for complete documentation of functions
//
//  string class consistent with a subset of the standard C++ string class
//  as defined in the draft ANSI standard
// *******************************************************************

#include <string.h>
#include <assert.h>
#include <stdlib.h>
#include <ctype.h>
#include "apstring.h"

const int npos = -1;

apstring::apstring()
// postcondition: string is empty
{
    myLength = 0;
    myCapacity = 1;
    myCstring = new char[myCapacity];
    myCstring[0] = '\0';           // make c-style string zero length
}

apstring::apstring(const char * s)
//description:   constructs a string object from a literal string
//               such as "abcd"
//precondition:  s is '\0'-terminated string as used in C
//postcondition: copy of s has been constructed
{
    assert (s != 0);               // C-string not NULL?
    myLength = strlen(s);
    myCapacity = myLength + 1;      // make room for '\0'
    myCstring = new char[myCapacity];
    strcpy(myCstring,s);
}

apstring::apstring(const apstring & str)
//description:   copy constructor
//postcondition: copy of str has been constructed
{
    myLength = str.length();
    myCapacity = myLength + 1;
    myCstring = new char[myCapacity];
    strcpy(myCstring,str.myCstring);
}

apstring::~apstring()
//description:   destructor
//postcondition: string is destroyed
{
    delete[] myCstring;                // free memory
}

const apstring& apstring::operator =(const apstring & rhs)
//postcondition: normal assignment via copying has been performed
{
    if (this != &rhs)                             // check aliasing
    {
        if (myCapacity < rhs.length() + 1)        // more memory needed?
        {
            delete[] myCstring;                   // delete old string
            myCapacity = rhs.length() + 1;        // add 1 for '\0'
            myCstring = new char[myCapacity];
        }
        myLength = rhs.length();
        strcpy(myCstring,rhs.myCstring);
    }
    return *this;
}

const apstring& apstring::operator = (const char * s)
//description:   assignment from literal string such as "abcd"
//precondition:  s is '\0'-terminated string as used in C
//postcondition: assignment via copying of s has been performed
{
    int len = 0;                         // length of newly constructed string
    assert(s != 0);                      // make sure s non-NULL
    len = strlen(s); // # of characters in string
    // free old string if necessary
    if (myCapacity < len + 1)
    {
	   delete[] myCstring;  // delete old string
	   myCapacity = len + 1;   // add 1 for '\0'
	   myCstring = new char[myCapacity];
    }
    myLength = len;
    strcpy(myCstring,s);
    return *this;
}

const apstring& apstring::operator = (char ch)
//description:   assignment from character as though single char string
//postcondition: assignment of one-character string has been performed
{
    if (myCapacity < 2)
    {
        delete [] myCstring;
        myCapacity = 2;
        myCstring = new char[myCapacity];
    }
    myLength = 1;
    myCstring[0] = ch;  // make string one character long
    myCstring[1] = '\0';

    return *this;
}

int apstring::length( ) const
//postcondition: returns # of chars in string
{
    return myLength;
}

const char * apstring::c_str() const
//description:   convert string into a '\0'-terminated string as
//               used in C for use with functions
//               that have '\0'-terminated string parameters.
//postcondition: returns the equivalent '\0'-terminated string
{
    return myCstring;
}

char& apstring::operator[](int k)
// precondition:  0 <= k < length()
// postcondition: returns copy of the kth character
// note:          if this reference is used to write a '\0'
//                subsequent results are undefined
{
    if (k < 0 || myLength <= k)
    {
        cerr << "index out of range: " << k << " string: " << myCstring
            << endl;
        exit(1);
    }
    return myCstring[k];
}


char apstring::operator[](int k) const
// precondition:  0 <= k < length()
// postcondition: returns copy of the kth character
{
    if (k < 0 || myLength <= k)
    {
        cerr << "index out of range: " << k << " string: " << myCstring
            << endl;
        exit(1);
    }

    return myCstring[k];
}

ostream& operator <<(ostream & os, const apstring & str)
//postcondition: str is written to output stream os
{
    return os << str.c_str();
}

istream& operator >>(istream & is, apstring & str)
//precondition:  input stream is open for reading
//postcondition: the next string from input stream is has been read
//               and stored in str
{
    char ch;
    str = "";    // empty string, will build one char at-a-time
    is >> ch;    // whitespace skipped, first non-white char in ch


    if (! is.fail())
    {
        do
        {
            str += ch;
            is.get(ch);
        } while (! is.fail() && ! isspace(ch));
  
        if (isspace(ch))    // put whitespace back on the stream
        {
            is.putback(ch);     
        }
    }
 
    return is;
}

istream & getline(istream & is, apstring & str)
//description:   reads a line from input stream is into the string str
//precondition:  input stream is open for reading
//postcondition: chars from input stream is up to '\n' have been read
{
    char ch;
    str = "";     // empty string, will build one char at-a-time
  
    while (is.get(ch) && ch != '\n')
    {
        str += ch;
    }
 
    return is;
}

const apstring& apstring::operator +=(const apstring & str)
//postcondition: concatenates a copy of str onto this string
{
    apstring copystring(str);         // copy to avoid aliasing problems

    int newLength = length() + str.length(); // self + added string
    int lastLocation = length();      // index of '\0'

    // check to see if local buffer not big enough
    if (newLength >= myCapacity)
    {
        myCapacity = newLength + 1;
		   if (str.length() == 1)  // special case for catenating one char
		   {                       // make room for future catenations
		       myCapacity *= 2;
		   }
        char * newBuffer = new char[myCapacity];
        strcpy(newBuffer,myCstring); // copy into new buffer
        delete [] myCstring;       // delete old string
        myCstring = newBuffer;
    }

    // now catenate str (copystring) to end of myCstring
    strcpy(myCstring+lastLocation,copystring.c_str() );
    myLength = newLength;           // update information

    return *this;
}

const apstring & apstring::operator += ( char ch )
// postcondition: concatenates a copy of ch onto this string
{
    apstring temp;   // make string equivalent of ch
    temp = ch;
    *this += temp;
    return *this;
}

apstring operator +(const apstring & lhs, const apstring & rhs)
// postcondition: returns concatenation of lhs with rhs
{
    apstring result(lhs);  // copies lhs to result
    result += rhs;   // catenate rhs
    return result;   // returns a copy of result
}

apstring operator + ( char ch, const apstring & str )
// postcondition: returns concatenation of ch with str
{
    apstring result; // make string equivalent of ch
    result = ch;
    result += str;
    return result;
}

apstring operator + ( const apstring & str, char ch )
// postcondition: returns concatenation of str with ch
{
    apstring result(str);
    result += ch;
    return result;
}

apstring apstring::substr(int pos, int len) const
//description:   extract and return the substring of length len starting
//               at index pos
//precondition:  this string represents c0, c1, ..., c(n-1)
//               0 <= pos <= pos + len - 1 < n.
//postcondition: returns the string that represents
//               c(pos), c(pos+1), ..., c(pos+len-1)
//
{
    if (pos < 0)                       // start at front when pos < 0
    {
       pos = 0;
    }

    if (pos >= myLength) return "";     // empty string
    int lastIndex = pos + len - 1;      // last char's index (to copy)
    
	if (lastIndex >= myLength)          // off end of string?
    {
        lastIndex = myLength-1;
    }
    apstring result(*this);               // make sure enough space allocated
    int j,k;
    for(j=0,k=pos; k <= lastIndex; j++,k++)
    {
        result.myCstring[j] = myCstring[k];
    }
    result.myCstring[j] = '\0';         // properly terminate C-string
    result.myLength = j;                // record length properly
    return result;
}

int apstring::find(const apstring & str)  const
//description:   find the first occurrence of the string str within this
//               string and return the index of the first character.  If
//               str does not occur in this string, then return npos.
//precondition:  this string represents c0, c1, ..., c(n-1)
//               str represents s0, s1, ...,s(m-1)
//postcondition: if s0 == ck0, s1 == ck1, ..., s(m-1) == ck(m-1) and
//               there is no j < k0 such that s0 = cj, ...., sm == c(j+m-1),
//               then returns k0;
//               otherwise returns npos
{
    int len = str.length();
    int lastIndex = length() - len;
    int k;
    for(k=0; k <= lastIndex; k++)
    {
        if (strncmp(myCstring + k,str.c_str(),len) == 0) return k;
    }
    return npos;
}

int apstring::find( char ch ) const
// description:   finds the first occurrence of the character ch within this
//                string and returns the index.  If ch does not occur in this
//                string, then returns npos.
// precondition:  this string represents c0, c1, ..., c(n-1)
// postcondition: if ch == ck, and there is no j < k such that ch == cj
//                then returns k;
//
#ifndef _APSTRING_H
#define _APSTRING_H

#include <iostream.h>
// uncomment line below if bool not built-in type
// #include "bool.h"

// *******************************************************************
//  Last Revised: 11/24/98 - corrected specification comments, dhj
//
//  8/14/98 corrected comments, dhj
//  6/29/98 - commented out the #include "bool.h", dhj
//
//  APCS string class
//
//  string class consistent with a subset of the standard C++ string class
//  as defined in the draft ANSI standard
// *******************************************************************

extern const int npos;  // used to indicate not a position in the string

class apstring
{
  public:

  // constructors/destructor

    apstring( );                         // construct empty string ""
    apstring( const char * s );          // construct from string literal
    apstring( const apstring & str );    // copy constructor
    ~apstring( );                        // destructor

  // assignment

    const apstring & operator = ( const apstring & str ); // assign str
    const apstring & operator = ( const char * s );       // assign s
    const apstring & operator = ( char ch );              // assign ch

  // accessors

    int    length( )                  const;    // number of chars
    int    find( const apstring & str ) const;  // index of first occurrence of str
    int    find( char ch )            const;    // index of first occurrence of ch
    apstring substr( int pos, int len ) const;    // substring of len chars
                                                // starting at pos
    const char * c_str( )             const;    // explicit conversion to char *

  // indexing

    char   operator[ ]( int k )       const;    // range-checked indexing
    char & operator[ ]( int k );                // range-checked indexing

  // modifiers

    const apstring & operator += ( const apstring & str );// append str
    const apstring & operator += ( char ch );            // append char


  private:
      int myLength;                     // length of string (# of characters)
      int myCapacity;                   // capacity of string
      char * myCstring;                 // storage for characters
};

// The following free (non-member) functions operate on strings
//
// I/O functions

ostream & operator << ( ostream & os, const apstring & str );
istream & operator >> ( istream & is, apstring & str );
istream & getline( istream & is, apstring & str );

// comparison operators:

bool operator == ( const apstring & lhs, const apstring & rhs );
bool operator != ( const apstring & lhs, const apstring & rhs );
bool operator <  ( const apstring & lhs, const apstring & rhs );
bool operator <= ( const apstring & lhs, const apstring & rhs );
bool operator >  ( const apstring & lhs, const apstring & rhs );
bool operator >= ( const apstring & lhs, const apstring & rhs );

// concatenation operator +

apstring operator + ( const apstring & lhs, const apstring & rhs );
apstring operator + ( char ch, const apstring & str );
apstring operator + ( const apstring & str, char ch );

// *******************************************************************
// Specifications for string functions
//
// Any violation of a function's precondition will result in an error
// message followed by a call to exit.
//
// The apstring class assumes that '\0' is not a valid
// character in an apstring. Any attempts to place '\0'
// in an apstring will result in undefined behavior. Generally
// this means that characters that follow the '\0' will not
// be considered part of the apstring for purposes of
// comparison, output, and subsequent copying.
//
// constructors / destructor
//
// string( )
//    postcondition: string is empty
//
// string( const char * s )
//    description:   constructs a string object from a literal string
//                   such as "abcd"
//    precondition:  s is '\0'-terminated string as used in C
//    postcondition: copy of s has been constructed
//
// string( const string & str )
//    description:   copy constructor
//    postcondition: copy of str has been constructed
//
// ~string( );
//    description:   destructor
//    postcondition: string is destroyed
//
// assignment
//
// string & operator = ( const string & rhs )
//    postcondition: normal assignment via copying has been performed
//
// string & operator = ( const char * s )
//    description:   assignment from literal string such as "abcd"
//    precondition:  s is '\0'-terminated string as used in C
//    postcondition: assignment via copying of s has been performed
//
// string & operator = ( char ch )
//    description:   assignment from character as though single char string
//    postcondition: assignment of one-character string has been performed
//
// accessors
//
// int length( ) const;
//    postcondition: returns # of chars in string
//
// int find( const string & str)  const;
//    description:   find the first occurrence of the string str within this
//                   string and return the index of the first character.  If
//                   str does not occur in this string, then return npos.
//    precondition:  this string represents c0, c1, ..., c(n-1)
//                   str represents s0, s1, ...,s(m-1)
//    postcondition: if s0 == ck0, s1 == ck1, ..., s(m-1) == ck(m-1) and
//                   there is no j < k0 such that s0 = cj, ...., sm == c(j+m-1),
//                   then returns k0;
//                   otherwise returns npos
//
// int find( char ch ) const;
//    description:   finds the first occurrence of the character ch within this
//                   string and returns the index.  If ch does not occur in this
//                   string, then returns npos.
//    precondition:  this string represents c0, c1, ..., c(n-1)
//    postcondition: if ch == ck, and there is no j < k such that ch == cj
//                   then returns k;
//                   otherwise returns npos
//
// string substr( int pos, int len ) const;
//    description:   extract and return the substring of length len starting
//                   at index pos
//    precondition:  this string represents c0, c1, ..., c(n-1)
//                         0 <= pos <= pos + len - 1 < n.
//    postcondition: returns the string that represents
//                   c(pos), c(pos+1), ..., c(pos+len-1)
//
// const char * c_str( ) const;
//    description:   convert string into a '\0'-terminated string as
//                   used in C for use with functions
//                   that have '\0'-terminated string parameters.
//    postcondition: returns the equivalent '\0'-terminated string
//
// indexing
//
// char operator [ ]( int k ) const;
//    precondition:  0 <= k < length()
//    postcondition: returns copy of the kth character
//
// char & operator [ ]( int k )
//    precondition:  0 <= k < length()
//    postcondition: returns reference to the kth character
//    note:          if this reference is used to write a '\0'
//                   subsequent results are undefined
//
// modifiers
//
// const string & operator += ( const string & str )
//    postcondition: concatenates a copy of str onto this string
//
// const string & operator += ( char ch )
//    postcondition: concatenates a copy of ch onto this string
//
//
// non-member functions
//
// ostream & operator << ( ostream & os, const string & str)
//    postcondition: str is written to output stream os
//
// istream & operator >> ( istream & is, string & str )
//    precondition:  input stream is open for reading
//    postcondition: the next string from input stream is has been read
//                   and stored in str
//
// istream & getline( istream & is, string & str )
//    description:   reads a line from input stream is into the string str
//    precondition:  input stream is open for reading
//    postcondition: chars from input stream is up to '\n' have been read
//                   and stored in str; the '\n' has been read but not stored
//
// string operator + ( const string & lhs, const string & rhs )
//    postcondition: returns concatenation of lhs with rhs
//
// string operator + ( char ch, const string & str )
//    postcondition: returns concatenation of ch with str
//
// string operator + ( const string & str, char ch )
//    postcondition: returns concatenation of str with ch
//
//***************************************************************
#endif
#include "bank.h"

//constructors
bank::bank ()
//default constructor
{}

bank::~bank ()
//destructor
{}

//modifiers
bank::deposit (const double &amount, apstring savcheck)
//This function gets an amount and word which indicated which account the amount should be deposited to
{
	if (savcheck == "checking" || savcheck == "Checking")
		checking.deposit (amount);
	else 
		savings.deposit (amount);
}

bank::withdraw (const double &amount, apstring savcheck)
//This function gets an amount and word which indicated which account the amount should be withdrawn from
{
	if (savcheck == "checking" || savcheck == "Checking")
		checking.withdrawal (amount);
	else 
		savings.withdrawal (amount);
}

bank::transfer (const double &amount, apstring savcheck)
//This function gets an amount and word which indicated which account the amount should be withdrawn and be deposited to
{
	if (savcheck == "checking" || savcheck == "Checking")
	{
		checking.withdrawal (amount);
		savings.deposit (amount);
	}
	else 
	{
		savings.withdrawal (amount);
		checking.deposit (amount);
	}
}

//accessor
double bank::print_savings ()
//This function prints the balances of both accounts
{
	return savings.inquire ();
}

double bank::print_checking ()
//This function prints the balances of both accounts
{
	return checking.inquire ();
}

double bank::goto_interest ()
//This is a helper function to link the account class member function interest to the main program
{
	return savings.interest ();
}
2
Contributors
2
Replies
3
Views
11 Years
Discussion Span
Last Post by Ancient Dragon
0

this are the other codes:

Attachments
//Jun Nozaki	10/17/2000	This is the header file for the bank class.
//basically an extension to the account class... this class uses the account class
//to simulate a bank account with savings+checking

#ifndef _BANK_H
#define _BANK_H

#include "account.h"
#include "apstring.h"
#include <iostream.h>

class bank
{
	public:
		//constructors
		bank ();
		~bank ();

		//modifiers
		deposit (const double &amount, apstring savcheck);
		withdraw(const double &amount, apstring savcheck);
		transfer(const double &amount, apstring savcheck);
		
		//accessors
		double print_savings ();
		double print_checking ();
		double goto_interest ();
	
	private:
		account savings; //holds the savings information
		account checking; //holds the checking information
};

#endif
// Jun Nozaki	10/22/2000	Bank Test program: This program will test the bank and account class, it will be menu driven 
//and will act according to the  users input. 

#include <iostream.h>
#include "apstring.h"  //basic string class, I included it in the zip file, but it can be found on the collegeboard website
#include "account.h"   //my personal class for holding account information, its really basic
#include "bank.h"      //my personal class for holding information about savings and checking
#include <fstream.h>   //for output to amount file
#include <iomanip.h>   //spacing
#include <assert.h>    


void dep (bank &user, double &amount, apstring savcheck, int savnumber, ofstream &savfile, apstring checknumber, ofstream &checkfile, apstring &payee);
void with (bank &user, double &amount, apstring savcheck, int savnumber, ofstream &savfile, apstring &checknumber, ofstream &checkfile, apstring &payee);
void trans (bank &user, double &amount, apstring savcheck, int savnumber, ofstream &savfile, apstring checknumber, ofstream &checkfile);
void print (bank &user, apstring savcheck);
void inquire (bank &user);
void savings_file (bank &user, int &savnumber, ofstream &savfile, apstring operation, double amount);
void checking_file (bank &user, apstring checknumber, ofstream &checkfile, apstring payee, double amount);


int main ()
{
	bool done = 0, back = 0;
	bank user;
	int choice = 0, savnumber = 0, choice2 = 0;
	double amount = 0;
	apstring savcheck, payee, checknumber;
	ofstream savfile, checkfile;
	assert (!savfile.fail());
	
	savfile.open ("savings.txt");
	checkfile.open ("checking.txt");
	assert (!checkfile.fail());
	savfile << "+-------------------+---------------------------+-------------+-------------+\n";
	savfile << "|" << setw(16) << "Transaction #" << setw (4) <<  "|" << setw(22) << "Transaction Type" << setw (6) << "|" << setw (10) << "Amount" << setw (4) << "|" << setw(10) << "Balance" <<setw (5) << "|\n";
	savfile << "+-------------------+---------------------------+-------------+-------------+\n";
	checkfile << "+-----------+-----------------------------------+-------------+-------------+\n";
	checkfile << "|" << setw (9) << "Check #" << setw (3) << "|" << setw (20) << "Payee" << setw (16) << "|" << setw (10) << "Amount" << setw (4) << "|" << setw(10) << "Balance" << setw (5) << "|\n";
	checkfile << "+-----------+-----------------------------------+-------------+-------------+\n";
	cout << setiosflags (ios::fixed|ios::showpoint);
	cout << setprecision (2);
	cout << "Welcome to the Williston Bank!\n";
	cout << "\nPlease enter your starting balance (Checking): $";
	cin  >> amount;
	user.deposit (amount, "checking");
	checking_file (user, checknumber, checkfile, "Starting Balance", amount);
	cout << "Please enter your starting balance  (Savings): $";
	cin  >> amount;
	user.deposit (amount, "savings");
	savings_file (user, savnumber, savfile, "Starting Balance", amount);
	savnumber++;
	amount = user.goto_interest ();
	cout << "You earned $" << amount << " interest this month.\n";
	user.deposit (amount, "savings");
	cout << "Your current savings balance is: $" << user.print_savings ();
	savings_file (user, savnumber, savfile, "Interest", amount);
	savnumber++;


	while (! done)
	{
		cout << "\n\n\t1. Checking\n";
		cout << "\t2. Savings\n";
		cout << "\t0. Quit\n";
		cout << "\nPlease enter which account you want to use: ";
		cin  >> choice;

		switch (choice)
		{
			case 1 : savcheck = "Checking";
					 back = 0;
				break;
			case 2 : savcheck = "Savings";
					 back = 0;
				break;
			case 0 : done = 1;
					 back = 1;
				break;
			default : cout << "You entered an invalid entry, please reconsider it.\n";
				break;
		}

		while (! back)
		{
			cout << "\n\t1. Deposit\n";
			cout << "\t2. Withdrawal\n";
			cout << "\t3. Transfer\t\t\t\tYou are in your\n";
			cout << "\t4. Print Balances\t\t\t" << savcheck << " acount\n";
			cout << "\t0. Return to previous menu\n";
			cout << "\nSelect amount transaction: ";
			cin  >> choice2;
			cout << endl;

			switch (choice2)
			{
				case 1 : dep   (user, amount, savcheck, savnumber, savfile, checknumber, checkfile, payee);
						 if (savcheck == "Savings" || savcheck == "savings") savnumber++;
						 print (user, savcheck);
					break;
				case 2 : with  (user, amount, savcheck, savnumber, savfile, checknumber, checkfile, payee);
 						 if (savcheck == "Savings" || savcheck == "savings") savnumber++;
						 print (user, savcheck);
					break;
				case 3 : trans (user, amount, savcheck, savnumber, savfile, checknumber, checkfile);
						 savnumber++;
						 print (user, savcheck);
					break;
				case 4 : inquire (user);
					break;
				case 0 : back = 1;
					break;
				default : cout << "You entered an invalid entry, please reconsider it.\n";
					break;
			}
		}
	}
	cout << "\nThank you for using the Williston Bank!\n";
	cout << "You can access the data to your accounts using amount wordprocessor.\n";
	cout << "The file names are: 'savings.txt' and 'checking.txt'\n\n";
			
	savfile <<   "+-------------------+---------------------------+-------------+-------------+";
	checkfile << "+-----------+-----------------------------------+-------------+-------------+";

	return 0;
}
		

void dep (bank &user, double &amount, apstring savcheck, int savnumber, ofstream &savfile, apstring checknumber, ofstream &checkfile, apstring &payee)
//This function will ask the user for the amount that should be deposited and deposits it to the right account
{
	cout << "Please enter the amount of money you want to deposit: $";
	cin  >> amount;
	if (savcheck == "Checking" || savcheck == "checking")
	{
		if (amount >= 0)
		{
			user.deposit (amount, savcheck);
			checking_file (user, checknumber, checkfile, "Deposit", amount);
		}
		else cout << "You entered an invalid entry, please reconsider it.\n";
	}
	else
	{
		if (amount >= 0)
		{
			user.deposit (amount, savcheck);
			savings_file (user, savnumber, savfile, "Deposit", amount);
		}
		else cout << "You entered an invalid entry, please reconsider it.\n";
	}
}

void with (bank &user, double &amount, apstring savcheck, int savnumber, ofstream &savfile, apstring &checknumber, ofstream &checkfile, apstring &payee)
//This function will ask the user for the amount that should be withdrawn and withdraws it from the right account
{
	cout << "Please enter the amount of money you want to withdraw: $";
	cin  >> amount;
	getline (cin, payee);
	if (savcheck == "Checking" || savcheck == "checking")
	{
		if (amount <= user.print_checking())
		{
			user.withdraw (amount, savcheck);
			cout << "Please enter the checknumber: ";
			getline (cin, checknumber);
			cout << "Please enter whose order the check should be paid to: ";
			getline (cin, payee);
			checking_file (user, checknumber, checkfile, payee, amount);
		}
		else cout << "You entered an invalid entry, please reconsider it.\n";
	}
	else
	{
		if (amount <= user.print_savings())
		{
			user.withdraw (amount, savcheck);
			savings_file (user, savnumber, savfile, "Withdrawal", amount);
		}
		else cout << "You entered an invalid entry, please reconsider it.\n";
	}
}

void trans (bank &user, double &amount, apstring savcheck, int savnumber, ofstream &savfile, apstring checknumber, ofstream &checkfile)
//This function will ask the user from which account he/she wants to transfer and the amount that should be transfered
{
	cout << "Please enter the amount of money you want to transfer: $";
	cin  >> amount;
	if (savcheck == "Checking" || savcheck == "checking")
	{
		if (amount <= user.print_checking())
		{
			user.transfer (amount, savcheck);
			savings_file (user, savnumber, savfile, "Transf from Checking", amount);
			checking_file (user, " ", checkfile, "Transf to Savings", amount);
		}
		else cout << "You entered an invalid entry, please reconsider it.\n";
	}
	else
	{		
		if (amount <= user.print_savings())
		{
			user.transfer (amount, savcheck);
			savings_file (user, savnumber, savfile, "Transf to Checking", amount);
			checking_file (user, " ", checkfile, "Transf from Savings", amount);
		}
		else cout << "You entered an invalid entry, please reconsider it.\n";
	}		
}

void print (bank &user, apstring savcheck)
//This function prints the balance of either the checking or the savings account
{
	if (savcheck == "Checking" || savcheck == "checking")
		cout << "Current Checking balance: $" << user.print_checking () << endl;
	else	
		cout << "Current Savings balance: $" << user.print_savings () << endl;
}

void inquire (bank &user)
//This function pritns out the balances for both accounts
{
	cout << "Current Checking balance: $" << user.print_checking () << endl;
	cout << "Current Savings balance: $" << user.print_savings () << endl;
}

void savings_file (bank &user, int &savnumber, ofstream &savfile, apstring operation, double amount)
//This function will output all the savings account transactions to amount text file "savings.txt"
{
	savfile << "|" << setw (10) << savnumber << setw (10) << "|" << setw (22) << operation << setw (6) << "|" << setw (10) << amount << setw (4) << "|" << setw (10) << user.print_savings () << setw (5) << "|\n";
}

void checking_file (bank &user, apstring checknumber, ofstream &checkfile, apstring payee, double amount)
//This function will output all the checking account transactions to amount text file "checking.txt"
{
	checkfile << "|" << setw (6) << checknumber << setw (6) << "|" << setw (26) <<  payee << setw (10) << "|" << setw (8) << amount << setw (6) << "|" << setw (8) << user.print_checking () << setw (7) << "|\n";
}
0

Here are just a few helpful hints: They are not all inclusive and you will no doubt encount other problems during the porting process.

1. rename the *.cpp files to *.c files
2. convert the classes in the .h files to normal structures and make the class methods just standard C functions, passing an instance of the structure to the function.

3. delete the class constructors and destructors. They are not relevant to C language.
4. replace functions such as void account::deposit (const double &amount) to standard c functions, such the following, adding an instance of the structure as the first parameter. objects passed by reference have to be passed as pointers, not c++ references.

void deposit (struct account * acct, const double*amount)
{
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.