0% found this document useful (0 votes)
151 views

01 Lab Manual COMRO1 - Programming Basics

This document is a laboratory manual for an introductory computer programming course. It contains 4 labs that introduce students to writing, compiling, and running simple C++ programs. Lab 1 has students compile and run their first program. Lab 2 introduces a syntax error. Lab 3 demonstrates a runtime error. Lab 4 has students write a program to convert kilometers to miles and debug any logic errors. The document also includes sample code, expected outputs, grading criteria, and review questions for each lab.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
151 views

01 Lab Manual COMRO1 - Programming Basics

This document is a laboratory manual for an introductory computer programming course. It contains 4 labs that introduce students to writing, compiling, and running simple C++ programs. Lab 1 has students compile and run their first program. Lab 2 introduces a syntax error. Lab 3 demonstrates a runtime error. Lab 4 has students write a program to convert kilometers to miles and debug any logic errors. The document also includes sample code, expected outputs, grading criteria, and review questions for each lab.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

DE LA SALLE LIPA

COLLEGE OF INFORMATION TECHNOLOGY AND ENGINEERING


COMPUTER ENGINEERING DEPARTMENT
COMPRO1 – COMPUTER PROGRAMMING 1 LABORATORY MANUAL

Name: Ramirez, Nerisse Allyztair M.


BSCpE – O1A

LABORATORY #1: Introduction to Programming and the Translation Process

I. METHODOLOGY

LAB 1.1 Opening, Compiling and Running Your First Program

1. Bring in the firstprog.cpp program from the Lab 1 folder.


2. Compile the program.
3. Run the program and write what is printed on the screen.

The code of firstprog.cpp is as follows:

// This is the first program that just writes out a simple message
// Place your name here

#include <iostream> // needed to perform C++ I/O using


namespace std; int main () { cout << "Now is the time for all good
men" << endl; cout << "To come to the aid of their party" <<
endl; return 0;
}

LAB 1.2 Compiling a Program with a Syntax Error

1. Bring in program semiprob.cpp from the Lab 1 folder.


2. Compile the program. Here we have our first example of the many syntax errors that you
no doubt will encounter in this course. The error message you receive may be different
depending on the system you are using, but the compiler insists that a semicolon is
missing somewhere. Unfortunately, where the message indicates that the problem exists,
and where the problem actually occurs may be two different places. To correct the
problem place a semicolon after the line cout<<"Todayisagreat dayforLab". Most syntax
errors are not as easy to spot and correct as this one.
3. Re-compile the program and when you have no syntax errors, run the program and input
9 when asked. Record the output.
4. Try running it with different numbers. Record your output.

The code of semiprob.cpp is as follows:

// This program demonstrates a compile error.


// Place your name here

#include <iostream>
using namespace std;
int main() {
int number; float total;
cout << "Today is a great day for Lab"
cout << endl << "Let's start off by typing a number of your choice" << endl;
cin >> number; total = number * 2;
cout << total << " is twice the number you typed" << endl; return
0;
}

LAB 1.3 Running a Program with a Run Time Error


1. Bring in program logicprob.cpp from the Lab 1 folder. The code follows.

// This program takes two values from the user and then swaps them
// before printing the values. The user will be prompted to enter
// both numbers.
// Place your name here

#include <iostream>
using namespace std;
int main() { float
firstNumber; float
secondNumber;

// Prompt user to enter the first number.


cout << "Enter the first number" << endl;
cout << "Then hit enter" << endl; cin >>
firstNumber;

// Prompt user to enter the second number.

cout << "Enter the second number" << endl;


cout << "Then hit enter" << endl; cin >>
secondNumber;

// Echo print the input.

cout << endl << "You input the numbers as " << firstNumber <<
" and " << secondNumber << endl;

// Now we will swap the values.

firstNumber = secondNumber; secondNumber = firstNumber;

// Output the values.

cout << "After swapping, the values of the two numbers are " <<
firstNumber << " and " << secondNumber << endl;

2|Page
return
0;
}

2. Compile this program. You should get no syntax errors.


3. Run the program. What is printed?
4. This program has no syntax or run time errors, but it certainly has a logic error. This logic
error may not be easy to find. Most logic errors create a challenge for the programmer. Your
instructor may ask you not to worry about finding and correcting the problem at this time.

LAB 1.4 Working with Logic Error

1. Develop a design that leads to an algorithm and a program that will read in a number that
represents the number of kilometers traveled. The output will convert this number to miles.
1 kilometer = 0.621 miles. Call this program kilotomiles.cpp.
2. Compile the program. If you get compile errors, try to fix them and re-compile until your
program is free of syntax errors.
3. Run the program. Is your output what you expect from the input you gave? If not, try to find
and correct the logic error and run the program again. Continue this process until you have
a program that produces the correct result.

II. OUTPUT
LAB 1.1

3|Page
LAB 1.2

LAB 1.3

4|Page
LAB 1.4

III. GRADING CRITERIA

Criteria Weight Rating


Functionality 40%
Coding 50%
Layout / Interface 10%
TOTAL 100%

IV. QUESTIONS
1. Compilers detect syntax and runtime errors.
2. Usually the most difficult errors to correct are the logic errors, since they are not detected
in the compilation process.
3. Attaching other pre-written routines to your program is done by the link process.
4. Binary code is the machine code consisting of ones and zeroes that is read by the computer.
5. Dividing by zero is an example of a Mathematical error.

5|Page
V. CONCLUSION

To conclude, I was able to familiarize with the basics of C++ in terms of understanding
basics of program design and algorithm, discovering different types of computer errors,
learning how an editor and compiler functions a program, and being able to code and run
a program simple.

Prepared by: Noted by:

Engr. Eloisa G. Lecaroz Engr. Agnes Z. Perez


Subject Teacher Department Chair

6|Page

You might also like