Lab 1 - Intro To Comp Programs
Lab 1 - Intro To Comp Programs
INTRODUCTION TO COMPUTER
PROGRAMS
Learning Outcomes
After completing this lab, you will be able to:
o know the Interactive Development Environment (IDE)
o know how to edit a program
o know how to compile and run a program
A. PRE-LAB ACTIVITIES
Question 1
What is a computer program?
Answer
Question 2
Name TWO (2) types of computer languages.
Answer
Question 3
What is the only language that a computer can directly understand?
Answer
Question 4
Give an example of low-level programming language.
1
Answer
Question 5
What type of computer language uses English-like abbreviations for machine language
instructions?
Answer
Question 6
List FIVE (5) examples of high level programming languages.
Answer
Question 7
What is a compiler?
Answer
Question 8
What is the purpose of the preprocessing directive?
#include <iostream>
Answer
Question 9
What purpose do braces serve?
Answer
2
3
Question 10
What are the symbols used to write comments?
Answer
Question 11
What is a source code?
Answer
Question 12
What is an object code?
Answer
4
B. LAB ACTIVITIES
Exercise 1
int main()
{
cout << "Hello world!" << endl;
return 0;
}
Program 1.1
a. Compile the program. If error messages appear, write down all the errors.
b. Check your program carefully. Compile and run the program again until no
errors appear. What is the program output?
Exercise 2
Edit your program according to the following program statements. Save your program
as lab1_prog2.cpp.
int main()
{
cout << “Hello ”;
cout << “world!” << endl;
return 0;
}
Program 1.2
5
6
a. Compile the program. If error messages appear, write down all the errors.
b. Check your program carefully. Compile and run the program again until no
errors appear. What is the program output?
c. Compare Program 1.1 and Program 1.2. What is the difference between these
two programs?
Exercise 3
Edit your program according to the following program statements. Save your program
as lab1_prog3.cpp.
int main()
{
cout << “Hello” << endl;
cout << “world!” << endl;
return 0;
}
Program 1.3
a. Compile the program. If error messages appear, write down all the errors.
b. Check your program carefully. Compile and run the program again until no
errors appear. What is the program output?
7
c. Compare Program 1.2 and Program 1.3. What is the difference between these
two programs?
Exercise 4
Edit Program 1.3 by changing Hello and world to your name and student ID, save
your program as lab1_prog4.cpp. Compile and run after the modification.
Exercise 5
int main()
{
cout << (14 + 4 – 8 / 2) << endl;
return 0;
}
Program 1.4
8
a. Compile and run the program. What is the output?
Exercise 6
int main()
{
cout << “5 + 2 = ” << (5 + 2) << endl;
return 0;
}
Program 1.6
9
Name :
Student ID :
Date :
C. POST-LAB ACTIVITIES
Question 1
* * * * * * * * * * * * * * * * * * *
* Thank You *
* Please come again. *
* * * * * * * * * * * * * * * * *
Question 2
10
Name :
Student ID :
Date :
Question 3
Write a program to display your own message. Your message must be at least five lines.
11