Lab 1 - Intro To Comp Programs

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 11

Lab 1

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

Type the following program statements. Save your program as lab1_prog1.cpp.

//Program Name: lab1_prog1.cpp


//This program is to display a message
#include <iostream>
using namespace std;

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.

//Program Name: lab1_prog2.cpp


//This program is to display a message
#include <iostream>
using namespace std;

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.

//Program Name: lab1_prog3.cpp


//This program is to display a message
#include <iostream>
using namespace std;

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.

a. What is the output?

b. What is the purpose of cout command in this program?

Exercise 5

Type the following program statements. Save your program as lab1_prog5.cpp.

//Program Name: lab1_prog5.cpp


//This program is to display a value
#include <iostream>
using namespace std;

int main()
{
cout << (14 + 4 – 8 / 2) << endl;
return 0;
}
Program 1.4

8
a. Compile and run the program. What is the output?

b. What is the purpose of cout command in this program?

Exercise 6

Type the following program statements. Save your program as lab1_prog6.cpp.

//Program Name: lab1_prog6.cpp


//This program is to display message and value
#include <iostream>
using namespace std;

int main()
{
cout << “5 + 2 = ” << (5 + 2) << endl;
return 0;
}
Program 1.6

a. Compile and run the program. What is the output?

9
Name :

Student ID :

Date :

C. POST-LAB ACTIVITIES
Question 1

Write a program to display output as below:

* * * * * * * * * * * * * * * * * * *
* Thank You *
* Please come again. *
* * * * * * * * * * * * * * * * *

Question 2

Write a program to display your name, address and telephone number.

10
Name :

Student ID :

Date :

Question 3

Write a program to display your own message. Your message must be at least five lines.

11

You might also like