Project Creation in C++

 

Creating and Executing a Dev-C++ 4 Application

Dev-C++ is a free programming environment. To get it, you can download it from http://www.bloodshed.net. If you decide to use it, you should help the developers with a financial contribution.

  1. Start Dev-C++ 4
     
  2. On the main menu, click File -> New Project...
  3. On the New Project dialog box, click the Project property sheet if necessary.
    Click Console Application
     
  4. Click OK.
  5. On the subsequent New Project dialog box, type Exercise to change the name of the project:
     
  6. Click OK. You will be asked to create a location for the project.
  7. Click the Create New Folder button .
  8. Type Exercise1 and press Enter.
  9. Double-click Exercise1 to display it in the Save In combo box:
     
  10. Click Save.
  11. Because the project has already been saved, it is better to save your C++ files as you go. As it happens, Dev-C++ has already created the first C++ file for you.
    Change the contents of the file as follows:
     
    #include <iostream.h>#include <stdio.h>int main(int argc, char *argv[]){cout << "C++ is Fun!!!";getchar();return 0;}
     
  12. To save the current C++ file, on the Main toolbar, click the Save button
  13. Type Exo as the name of the file.
  14. Click Save.
  15. To execute the program, on the main menu, click Execute -> Compile
     
  16. After the program has been compiled, click Execute.
  17. After viewing the program, press Enter to close the DOS window to return to Dev-C++
 

Borland C++BuilderX

 

Borland C++BuilderX is a commercial programming environment developed by Borland. To help programmers, Borland published a free version, called Personal Edition, that you can download and use for your lessons.

  1. On the main menu of C++BuilderX, click File -> New...
  2. In the Object Gallery dialog box, click New Console
     
  3. Click OK
  4. In the New Console Application - Step 1 of 3, enter the name of the new application in the Name edit box. In this case, you can type Exercise1
     
  5. Click Next
     
  6. In the New Console Application Wizard - Step 2 of 3, accept all defaults and click Next
  7. In the New Console Application Wizard - Step 3 of 3, click the check box under Create
  8. Click Untitled1 and delete it to replace it with Exercise
     
  9. Click Finish
  10. In the Project Content frame, double-click Exercise.cpp to display it in the right frame
     
  11. To execute the application, on the main menu, click Run -> Run Project

Borland C++ Builder (Console) Applications

  1. To create a console application in Borland C++ Builder, from the main menu, click File -> New (or File -> new -> Other):
     
  2. From the New Items dialog box. click the Console Wizard button and click OK.
  3. From the Console Wizard dialog box, click the C++ radio button and the Console Application check box (the other options are up to you but we will not use them in this tutorial):
     
  4. Click OK.
    A skeleton program is created for you. For this lesson, I would ask you to delete everything that appears in the Code Editor and type the two lines above, but leave it there. I will not address what all those words mean at this time and we don't even need them and don't care.
  5. Change the program as follows:
     
    //---------------------------------------------------------------------------#include <iostream.#include <conio>using namespace std;#pragma hdrstop//---------------------------------------------------------------------------#pragma argsusedint main(int argc, char* argv[]){    cout << "\nPress any key to continue...";    getch();    return 0;}//---------------------------------------------------------------------------
  6. To execute the program, on the main menu, click Run -> Run
  7. After viewing the result, press Enter to close the DOS window and return to Borland C++ Builder.

Linux C++ (Terminal) Applications

  1. I am using Red Hat Linux 7.2.
    To create a C++ application, open the Home Directory (it should have a shortcut on the top left corner of the desktop; otherwise, from the Taskbar, click Start -> KDE menus -> Home Directory)
  2. The title bar and the address combo box should display your username. For this exercise, I am logged with the root username. Therefore, my title bar and the address combo box display file:/root
    With your username selected, right-click in the right frame and click Create New -> Directory...
     
  3. Type Exercise1 and click OK
  4. On the right frame, make sure the Exercise1 directory is created (because I will refer to it).
  5. Start a text editor. I use gedit, which is available at Start -> Programs -> Applications -> gedit
  6. In the text editor, type the following:
     
    #include <iostream.h>int main(){    cout << C++ is fun!!!\n;    return 0;}
     
  7. Save your file. If you are using gedit like me, on the main menu, click File -> Save As... 
  8. Under the Directory header in the left list, double-click the Up One Level button ../
    If you see your user name in the left list, fine. Otherwise, double-click ../ again.
  9. On the left list, double-click your user name (for me that would be root/) to open you personal directory
  10. On the left list, double-click the Exercise1/ directory we created.
  11. In the Selection: text box, type the name of the file as Exo.cpp and click OK
  12. To execute the program, open the Terminal: Start -> System -> Terminal.
    In the Terminal window, you should see [UserName@localhost Username]$
    For example, mine is [root@localhost root]$
  13. This ensures that you are in your personal directory. To change to the directory that hosts your exercise, type cd Exercise1
    Now the new folder should be inside the square brackets. Mine is [Username@localhost Exercise1]$
  14. To compile the program, we will use the free g++ compiler. Therefore, type:
    g++ Exo.cpp
  15. For example, on mine, I type [jezoo@localhost Exercise1]$ g++ Exo.cpp
  16. You may receive one warning. For now, don't worry.
  17. To execute the program, type ./a.out and press Enter
  18. This is because the executable file, named a with the extension .out has been created one folder up from the actual location of the C++ file.
    For example, on mine, I type [root@localhost Exercise1]$ ./a.out
     
  19. To check the a.out file that was created when compiling, return to the Home Directory window and navigate to the /home/UserName/Exercise1/Exo

KDevelop C++ Projects

  1. To create program in KDevelop, start KDevelop by clicking Start -> Development ->KDevelop
     
  2. On the main menu, of KDevelop, click Project -> New...
  3. From the ApplicationWizard dialog box, in the list or projects, under the Terminal section, click C++ and click Next.
     
  4. In the Project Name edit box, type the name of the project. In this case, type Exercise2 and leave the other edit boxes "as is"; in other words, whatever they contain is fine
     
  5. Uncheck all of the check boxes (make them empty). This is just an option. If you leave them checked, the compiler would generate (a lot of) code for you and I will not have had time to explain those things to you.
  6. Click Next
  7. Make sure the VCS Support is set to NONE and click Next.
  8. Uncheck the headertemplate for .h-files check box (make it empty). Once again, we don't want the compiler to generate code that we haven't learned yet.
  9. Click Next.
  10. Uncheck the headertemplate for .cpp-files check box.
  11. Click Next.
  12. Notice the empty window: KDevelop is ready to create the project.
  13. Click Create.
  14. KDevelop will need a few seconds to create the project. When it has finished, its last line should be READY
     
  15. Therefore, click Exit.
  16. To create a (source) file, on the main menu, click File -> New...
  17. From the New File dialog box, click C/C++ File (*.cpp,*.c,*.cc,*.C ...)
  18. Type Main for the name of the file. Therefore, the Filename edit box should display Main.cpp (you can name the file anything you like, such as Exo or Exercise).
  19. Make sure the Add to Project check box is checked and click OK.
  20. Leave the grayed section on top of the file (it is just a set of comments that you don't need to delete; they will not affect your program).
  21. In the empty section of the file, type:
     
    #include <iostream>using namespace std;int main(){    cout << C++ is fun!!!\n;    return 0;}
  22. To execute the program, on the main menu, click Build -> Execute
    23. After viewing the program, press Enter to close the bash window

Microsoft Visual C++ Console Applications

  1. Start Microsoft Visual C++.
  2. On the main menu of Microsoft Visual C++ or Microsoft Visual Studio, click File -> New...
  3. Click the Projects property sheet.
  4. Click Win32 Console Application.
  5. In the Location box, type a drive followed by a folder name. For example, type C:\Programs\MSVC
  6. In the Project Name, type Exercise1
     
  7. Click OK.
  8. In the Win32 Console Application Step 1 of 1, click the An Empty Project radio button
     
  9. Click Finish.
  10. You will be presented with another dialog box. Click OK.
  11. To create a C++ file, on the main menu, click File -> New...
  12. In the New dialog box, make sure the Files property sheet is selected.
  13. Click C++ Source File
  14. In the File Name, type a name such as Exercise and click OK
  15. From what we have learned so far, change the contents of the file as follows:
     
    #include <iostream>using namespace std;int main(){    cout << "C++ is fun!!!\n";    return 0;}
  16. To execute the program, on the main menu, click Build -> Execute Exercise1.exe
  17. When asked to save the project, click Yes
  18. After viewing the result, press Enter to close the DOS window and return to MSVC.

Microsoft Visual C++ .NET Console Applications

  1. Start Microsoft Visual Studio .NET.
  2. On the main menu of Microsoft Development Environment, click File -> New -> Project...
  3. On the New Project dialog box, in the Location box (bottom of the dialog box), type a drive followed by a folder name such as C:\Programs\MSVC .Net 
  4. In the Project Type, click Visual C++ Projects
  5. In the Templates list view, click Win32 Project
  6. In the Name box, type Exercise1
     
  7. Click OK.
  8. In the Win32 Application Wizard - Exercise1 dialog box, click Application Settings
  9. In the Application Type section, click the Console Application radio button
  10. In the Additional Options section, click the Empty Project check box
     
  11. Click Finish.
  12. To create a new C++ file, on the main menu, click Project -> Add New Item... Or, on the Solution Explorer, right-click Exercise1 -> Add and click Add New Item...
  13. In the Categories list, make sure Visual C++ or C++ is selected.
  14. In the Templates list view, click C++ File (.cpp)
  15. In the Name box, replace the contents with Exercise
  16. Click Open
  17. From what we know about C++ already, change the contents of the file with:
     
    #include <iostream>using namespace std;int main(){    cout << "C++ is fun!!!\n";    return 0;}
  18. To execute the program, on the main menu, click Build -> Execute Exercise1.exe
  19. When asked to save the project, click Yes
  20. After viewing the result, press Enter to close the DOS window and return to MSVC.

Home Copyright 2000-2005 FunctionX, Inc.