Wednesday, July 21, 2010

C++: Intermission 1 - my first programs...

As a gesture of humor and to ease your stress in learning programming
(mostly from blindness perspective), I plan to share my own thoughts and
experiences as an apprentice programmer/student.

My very first program, apart from Hello World, was a unit converter
calculator. This program would convert between different units, including
length, temperature and so forth. This was a fun experiment that taught me
more about operator precedence, variable assignment and so forth.

Then came one of the first programming assignment from UCR: a madlib Story
Writer. Our instructor, Kris, asked us to write a madlib program - a text
story with certain fields, such as verbs left out. Since I was familiar with
this sort of thing (I used to see), I thought of creating a text file with a
story of my own, then leave out various words (mostly nouns and verbs) and
turn it into variables (strings). After assigning variables, I would put the
variables as part of the output. Then I would ask the user to write things
like nouns and verbs; using this information, I would "fill in the blank"
with user input, then display the output.

Back then, it was a program that span no more than fourty or fifty lines of
code. But as Kris taught us more "tricks' with C++, it became clear to me
that many programs, including Microsoft Outlook which I am using to compose
this email post, would have had hundreds and thousands of olines of code.
Then i asked myself, "how could this be possible?" The answer was dividing a
program into multiple files, or modules via functions (functions will be
covered later) and reusing parts of existing code.

This allows me to introduce the file extensions of some of the files you'll
be making, which are .cpp (C++ source code), .exe (executable, or a
program), .h (header file which will be used extensively later) and .o or
.obj (object files that a linker will use to produce the machine code).

For beginners: don't worry about all sorts of stress - I've been there too.
A general advice: ask a knowledge friend of yours to examine your code and
help you out, so that when you see a similar person, you can help him or her
out.

If you have any comments about these posts, please let me know via email or
feel free to comment on my blog posts.
Sources used: "Practical C++ Programming" from O'Reilly books, "C++ A
Dialog" from Steve heller.
// JL (UCR)

No comments:

Post a Comment