Hello all,
I've recently been asked to demonstrate the difference between Turbo C++ 3.0 and Visual C++ 2008. I'm not really familiar with the current coding standards, so I've enclosed a sample of Turbo C++ code. Please point out which functions are deprecated as well as their replacements.
#include <iostream.h>
#include <conio.h>
#include <ctype.h>
#include <string.h>
double cardNumber;
int is_looping = 1;
int loopTransact = 1;
class Billing
{
private:
double accountBalance;
public:
Billing (double openingBalance)
{
accountBalance = openingBalance;
}
void displayBalance()
{
cout << "Current Credit Card Balance for Card # " << cardNumber << " is: " << accountBalance << endl;
}
void creditToAccount()
{
double amount;
char merchantID[25];
cout << "Enter the amount to be credited: " << endl;
cin >> amount;
cout << endl;
cout << "Enter Merchant ID: " << endl;
cin >> merchantID;
cout << endl;
if (amount > 0)
{
accountBalance = accountBalance + amount;
cout << amount << " successfully charged to credit card by " << merchantID << "." << endl;
displayBalance();
}
else
{
cout << "Invalid amount specified. Amounts credited must be greater than 0." << endl;
getch();
creditToAccount();
}
}
void payBill()
{
if (accountBalance == 0)
{
cout << "Transaction invalid. Account has no outstanding bills." << endl;
return ;
}
double amount;
char tellerID[25];
cout << endl;
cout << "Enter Teller ID: " << endl;
cin >> tellerID;
cout << "Enter the amount paid by client: " << endl;
cin >> amount;
cout << endl;
if (amount > 0)
{
if (amount <= accountBalance)
{
accountBalance = accountBalance - amount;
cout << amount << " successfully paid." <<endl;
cout << "Transaction handled by Teller # " << tellerID << endl;
displayBalance();
}
else
{
cout << "Invalid amount specified. Amounts paid must not be greater than the account balance." << endl;
getch();
payBill();
}
}
else
{
cout << "Invalid amount specified. Amounts paid must be greater than 0." << endl;
getch();
creditToAccount();
}
}
void selectionScreen()
{
clrscr();
while (is_looping == 1)
{
clrscr();
char selection[1];
cout << "Credit Card Account Management Terminal. "<< endl;
cout << endl;
cout << endl;
cout << endl;
cout << "Welcome, Merchant. "<< endl;
cout << endl;
cout << endl;
cout << endl;
cout << "1. Credit a Purchase." << endl;
cout << "2. Pay Credit Card Bill." << endl;
cout << "3. Show Existing Credit Amount." << endl;
cout << "Select a function to proceed." << endl;
cin >> selection;
char *check1 = "1", *check2 = "2", *check3 = "3";
if (strcmp(selection, check1) == 0)
{
creditToAccount();
break;
}
if (strcmp(selection, check2) == 0)
{
payBill();
break;
}
if (strcmp(selection, check3) == 0)
{
displayBalance();
break;
}
cout << "Invalid Selection." << endl;
getch();
}
cout << endl;
cout << endl;
char newTransactionYesNo[1];
while (loopTransact == 1 )
{
cout << "Would you like to make another transaction (y/n): ";
cin >> newTransactionYesNo;
char *stringYes = "Y", *stringNo = "N";
newTransactionYesNo[0] = toupper(newTransactionYesNo[0]);
if (strcmp(newTransactionYesNo, stringYes) == 0)
{
selectionScreen();
}
else
{
if (strcmp(newTransactionYesNo, stringNo) == 0)
{
cout << "Thank you for using our banking system." << endl;
getch();
is_looping = 0;
loopTransact = 0;
break;
}
else
{
cout << endl;
cout << "Invalid input." << endl;
}
getch();
}
}
}
};
int main(void)
{
clrscr();
cout << "Enter Credit Card Number: " ;
cin >> cardNumber;
Billing newAccount(0);
newAccount.selectionScreen();
return 0;
}
Also, I know that quite a few bad programming practices crept in, but I was rushing this code. Please point out what's wrong with it and what could be done to make it better.