01 Lab Manual COMRO1 - Programming Basics
01 Lab Manual COMRO1 - Programming Basics
I. METHODOLOGY
// This is the first program that just writes out a simple message
// 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;
}
// 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;
cout << endl << "You input the numbers as " << firstNumber <<
" and " << secondNumber << endl;
cout << "After swapping, the values of the two numbers are " <<
firstNumber << " and " << secondNumber << endl;
2|Page
return
0;
}
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
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.
6|Page