$24
Introduction:
The purpose of this lab is to explore and reinforce the concepts from the lecture section of CS 1428. Today we will cover creating and compiling a file using the Code::Blocks integrated development environment.
Directions:
1-Launch Code::Blocks on your own computer.
2- Create a new empty file by selecting File-New-Empty File.Now select File-Save File As…and name your file “your__last_name_lab0.cpp”.
3-As the first lines of your new file copy the following:
//Your Name
//CS1428
//Lab 0
The “//”indicates that a line is a comment that will be ignored by the compiler. Comments can be used to mark ownership of files or explain what blocks of code are doing.
4-The next line of your file should be:
#include <iostream
This tells Code::Blocks that you want to use commands which are defined in a library. You can include any number of blank lines to improve the readability of your code.
5-Your next line of code will be:
using namespace std;
This line is important when you’re using standard libraries like iostream.
6- Now type:
int main () {
This is the beginning of a function definition. Every C++ program must include a “main” function. Code::Blocks will probably autofill the closing “}” curly bracket. All of the code for a function must be written between these brackets.
7-For the first line of your main function type the instruction:
cout << “Hello World.” << endl;
This line will cause the text “Hello World” to be printed in the console and then will start a new line. The semicolon at the end of the line tells the compiler that you’ve finished the command and is very important. Every statement in C++ must end with a semicolon.
8-Use the “cout” statement to answer the following questions. Answer each question with a separate “cout” and end each statement with an “endl” to start a new line. Keep your answers short.
Do you have any programming experience?
What is the purpose of a compiler?
What is an algorithm?
What data type would you use to store a number that includes a decimal?
What is the name of the compiler we are using with the Code::Blocks IDE?
What would you change in this code in order to ensure that it will execute correctly on a Macintosh computer? Windows? Linux?
What is an “argument” in programming?
What type of value will your main function return?
What type of device is a computer monitor?
What area of computer science interests you most?
9-The last statement in your function should be:
return 0;
Make sure that you close the main function with a final curly bracket “}”.
10- Save your work. Use the “Build and Run” button to compile and execute your program. If there are any errors in your code they will be displayed in the Build Log window of Code::Blocks. Correct any errors that exist in your code. If there are no errors in your code you will see something like this (although these answers may not be correct):
11-Attach your .cpp file to the TRACS assignment and submit. You can leave whenever you’ve finished the assignment.