Monday, June 06, 2005

C and C++, what’s the difference?

Both C and C++ are developed by people at Bell Labs. The latter is a general purpose programming language that incorporates almost all of the capabilities of C but adds a lot of capabilities making it more powerful and flexible programming language nowadays.

C++ includes Object Oriented Programming (OOP) technique by introducing classes. But because of the existence of a lot of OOPrograms nowadays, we could not feel C++ in the programming world. The reason is, C++ is a “hard-code” PL where people sometimes neglect apparently because it is time-consuming to code and debug in this language.

C++ is considered as a system PL rather than an application PL. There is a big difference between system and application as we all knew it. Do you know that Microsoft Windows and its Applications, Linux and other operating systems are coded in C/C++? Well, it’s true. Try to download the codes of Linux in the internet and view the codes, you could see 6 million+ lines of codes in C/C++. Now, you could see how powerful C++ really is.

This blog is devoted to all people who knew C and want to learn about C++ and use it as a basic tool in solving basic problems in computing. To begin with, may I introduce to you the twin. COUT and CIN. Practically, they are just the same as printf and scanf in C, respectively. COUT and CIN are two basic commands used by the computer and user in interacting. Consider the program below:

#include
main()
{
int age;

cout<<”\nEnter your age: “;
cin>>age;
}

There are two things new to you here. The use of the twin and the header file iostream.h. Like C, we need header files for the definition of some commands, in this example, cout and cin. The two commands are defined under the iostream.h file. If you like you can open the file and read it. It is usually located in the INCLUDE folder inside TC.

Try to encode the example above in a C++ editor, and compile it using the menu COMPILE or using shortcuts. Then RUN it.


IMPORTANT:

Sometimes an error will prompt when running a program. Sometimes you have to set something in a newly copied C++ compiler. Just like C or Pascal, you have to go to the DIRECTORIES that is found in OPTIONS menu. Be sure that the INCLUDE and LIBRARY Directory are set in the right path.

Another thing to consider is the TCDEF file that is sometimes set as read-only. This should not be a read-only file. So just change the property.

These two things are very typical errors encountered by students/instructors during the first day of their class.

Consider adding the segment below to our first program.

If (age < 18)
cout<<”\You are not allowed to drink alcoholic beverage yet”;
else
cout<<”\You are allowed to drink alcoholic beverage”;

In the above segment, I want you to focus your attention to the semicolon right before the word “else”

0 Comments:

Post a Comment

<< Home