Computer Science I Chapter 1: Getting Started
Lab 1 Work: Due Monday September 8th 2008
Answers should be typed in a Word document following the rules below
To gain experience with
All modern computers offer their users an interface to their physical, electrical, and digital systems. Your computer's operating system provides fundamental services from behind the scenes. A large part of a computer's work is simply storing and retrieving data so that it can be available to use.
Put simply, the operating system takes care of a lot of the filing work - storing, moving and remembering where things are - so you can do useful things at a higher level. You interact with the operating system via a Graphic User Interface (GUI), for example a windowing system using a pointing device like a mouse, or a Command Line Interface, using only a keyboard and a single window.
What are some examples of tasks you would tell the computer to do via the operating system interface?
Type your answer in your lab document under heading R1
Operations like browsing the web and editing text in a word processor - most of the things you'd have the computer do - involve your operating system executing some program. The operating system itself is a program which is running all the time. It executes your instructions and, in turn, it can run other programs.
It is useful to think of a program as a sequence of instructions. Both executable instructions and digital data can be represented as files, for example, on your hard drive. Both are sequences of symbols, just like the letters that make up the words in this sentence. Your job as a programmer is of course to provide the instructions that operate on the data.
We will begin to get some experience with the operating system by finding a file. We will locate math.h, an include file used by C++. Use a search engine to search for "functions in math.h"
What is the main aim of math.h? What must a program do before using it?
Give 3 examples of functions and 3 examples of constants in math.h ?
Frequently in these labs you will be asked to compile a sample program. Below is a copy of a C++ program that displays a drawing. Copy and paste it into your compiler's editor, and from there save it as art.cpp.
Describe what you did.
Type your answer in your lab document under heading R2
#include <iostream> #include <string> using namespace std; int main() /* PURPOSE: Display an 'art' drawing */ { string s1 = " * * * * * * "; string s2 = " * * * * * "; string s3 = "__________________________________\n"; string s4 = "_________________________________________________________\n"; cout << s4 << s1 << s3 << s2 << s3; cout << s1 << s3 << s2 << s3; cout << s1 << s3 << s2 << s3; cout << s1 << s3 << s2 << s3; cout << s4 << s4 << s4 << s4 << s4; return 0; }
Once you have typed in (or, in this case, pasted in) a program, you need to to compile it to to create an executable file. Again, these steps depend on your compilation environment. Find out the steps for your computer system, then go ahead and compile art.cpp to an executable file.
Finally, execute the program. Once again, the steps depend on your computer system.
Describe what you did to execute the program.
Describe what happened when the program executed.