Introduction
Welcome to the C++ world! The goal of this WebQuest is to familiarize you with the fundamentals of the C++ programming language and to aid in your understanding of object-oriented programming. Along with learning how to create and execute C++ programs, you'll develop a firm grasp of the core ideas of C++ programming.
Task
Setting up your software environment
Process
Video Guide: Click here
Written Guide:
Step 1: Download and Install Dev C ++
Dev C++ is a discontinued C++ Integrated Development Environment (IDE) that provides a simplistic, friendly, and clutter-free interface for writing and testing C++ programs. To download Dev C++ follow these steps:
- Go to the Sourceforge hosted download page at SourceForge.net
- Click the green button labelled download
- Run the installer and follow the instructions to install Dev C++ on your computer
Step 2: Install a C++ compiler
To compile/ build and run C++ programs, you will first need to ensure that you have an appropriate compiler installed. If you followed the instructions above then the link provided will allow you to install a version of the Dev C++ program that is bundled with a suitable compiler. Otherwise, to install a suitable compiler you may follow these steps:
- Go to the MinGW download page at OSDN.net
- Download the latest version of the MinGW.OSDN Compiler Collection (GCC) compiler for your operating system by clicking the blue button labeled mingw-get-setup.exe
- Run the installer and follow the instructions to install GCC on your computer.
Step 3 (Optional): Configure Dev C++
You may go through the first-time startup configuration of the Dev C++ program to make the program more suitable for your personal use. The program will allow you to change the theme, font, etc.
Congratulations! You are now ready to write, compile and execute your first C++ code!
As is customary you will be writing a program to print "Hello World", "Your Name", and "Your Age". Follow the steps below!
Video Guide: Click here
Written Guide:
Step 1: Open your chosen IDE if one is not already open
Open an IDE such as Dev C++ or Visual Studio Code and create a new source file. Your C++ code will be written here.
Step 2: Write the Code
NB. In C++ you can add comments (non-executable text) by using double forward slashes (//) for single-line comments or enclose the comment between /* and */ for multi-line comments. Comments are ignored by the compiler and are used to explain the code or make it more readable for other pragrammers.
In the text editor, enter the following code:
#include <iostream> // This line includes the iostream header file, which contains input/output functions.
using namespace std; // This line allows you to use functions from the standard library without having to specify the namespace.
int main() // This line defines the main function, which is the starting point of the program.
{
cout << "Hello World" << endl; // This line outputs the message "Hello World" to the console.
cout << "Your name" << endl; // This line outputs the message "Your name" to the console.
cout << "Your age" << endl; // This line outputs the message "Your age" to the console.
return 0; // This line returns 0 to the operating system, indicating that the program has been executed successfully.
}
Step 3: Save the file
Compile the code using your chosen IDE, in Dev C++ you can achieve this with the keyboard shortcut F9, through the graphic menu at the top of the editor, or using the "Execute" text menu. Save the file as desired taking care to avoid using spaces. For example "hello_world.exe"
Step 4: Run the Executable File (.exe)
You can run the code when it has been successfully compiled by running the compiled application. In Dev C++ this can be achieved with the keyboard shortcut F10, through the graphic menu at the top of the editor, or using the "Execute" text menu. Otherwise, you can navigate to the directory it has been saved in and run the compiled file (.exe) from there by clicking it as you would open a normal program.
Step 5: Marvel at your work!
Congratulations! You have written and executed your first C++ program. You have taken the first step to becoming a competent C++ programmer.
Evaluation
Code Execution: The program should compile without errors.
The program should output the correct output to the console ("Hello World", "Your Name", and "Your Age").
The application should return 0 to the operating system, indicating that it was successfully executed.
Conclusion
Congratulations on completing this WebQuest! You have taken your first steps into the world of C++ programming. Continue to practice and build upon your new skills, and soon you will be writing complex programs with ease.