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.

Recommended Answers

All 7 Replies

A lot is wrong...

Compile with -Wall (enable all warnings) and it will tell you which functions are deprecated.

As a first sweep: don't use anything from conio.h

I see that getch(), clrscr() and strcmp() are deprecated, and that I seem to miss a few much-needed prototypes.

What are the equivalents for getch() clrscr() and strcmp()?

Come on that is trivial to find out.

First: understand why strcmp is deprecated, do you know why?

Come on that is trivial to find out.

First: understand why strcmp is deprecated, do you know why?

Not really.

Care to enlighten me?

I don't think conio.h is depraceted. I don't know other simple Windows terminal library, and in standard libraries you have only reading and writing to streams. You can use cin.get() instead of getch, but it doesn't exactly do the same. And how do you want to do clrscr() in standard c++?
Headers like iostream.h are depracated, you should change them to for example iostream, and use funtions from std namespace (std::cin), or declare using namespace std (don't do this in headers).
You shouldn't also flush cout so much, it is a bad practise (use '\n' instead of endl).

//Edit While reading selection in this program you write zero terminated string to one element char array. This is evil.

>>I don't think conio.h is depraceted
As for C and C++ standards go -- no it isn't because it was never part of the standards in the first place. It's compiler specific. I suppose a specific compiler can declare something depreciated if it wants to (Microsoft has declared most of the standard C functions in string.h depreciated).

>>And how do you want to do clrscr() in standard c++?
There is no standard way to do it.

I just discovered that.

I wrote a new function just for it, and removed conio.h

void clrscr(){

#ifdef WINDOWS
system("cls");
#else
system("clear");
#endif
}

Also, to note again, this was to demonstrate the difference between Turbo C++ 3.0 and Visual C++ 2008. The code in Turbo C++ is really bad because it was supposed to be. This is part of my report/push towards the class using a better IDE and modern standards.

commented: for trying to get rid of turbo c in education +34
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.