Search for notes by fellow students, in your own course and all over the country.

Browse our notes for titles which look like what you need, you can preview any of the notes via a sample of the contents. After you're happy these are the notes you're after simply pop them into your shopping cart.

My Basket

C language £0.50

Title: GETTING STARTED IN C++
Description: Introduction and Summary Terms Summary and Analysis Introduction to C++ Programs Problems Data Types Problems

Document Preview

Extracts from the notes are below, to see the PDF you'll receive please use the links above


GETTING STARTED IN C++
Introduction and Summary

C++ is a computer programming language that supports object-oriented
programming, meaning it is largely concerned with the manipulation of special
variables called objects
...
The general format of a C++
program starts with one or more header files, which contain predefined functions and
classes
...
After the header files come class
definitions and definitions of their respective member functions, followed by other
functions for your program
...
This is where program execution begins
...
Integers, characters, and floating point numbers form the crux of C++'s
primitive data types
...
Most
character values can be written as keyboard characters between single quotation
marks; however, some symbols require special escape sequences to represent the
character, such as the tab character '\\t'
...
You can create your
own kind of data type with the enum command, which allows you to specify the name
of your data type and the values it can take on
...

 Header File - A file ending in
...

 Syntax - The usage of a programming language command; the form in which a
statement must appear
...
"
 Main() - Where C++ programs begin execution; must be present in every C++
program
...
h header
file
...
E
...
: cout << "The average score is: " << 84
...
Functions are the
building blocks of full programs
...
Often used
to document the code
...

 Variables - Variables are symbols in a program that take on values and which
are manipulated for the purposes of the program
...

 Classes - Classes are collections of variables and functions, which together
form an coherent, abstract thing referred to as an object
...

 Member Function - Functions belonging to a particular class which manipulate
that class's data members
...

 Data Types - The possible types of variables
...

 Escape Sequence - Escape sequences are symbols that represent special
characters
...

 String - A sequence of characters, usually represented between quotation
marks
...
g
...
\\n"
 Constant - A constant is a variable whose value does not change for the
duration of a program
...
It must be
defined at declaration
...
Using the
keyword enum, a programmer can choose the values that each enumerated
variable can take on
...
h>

void main()
{
cout << "Hello World!\n";

/* this is pretty simple */

}

This program does almost nothing useful except that it gives a new programmer
some sense of how a program might be organized
...
Let's
look at the parts of this program:
The first line lets the programmer use extra functions, such as cout
...
h" files) like these at the start of your program in order to
use the functions/variables/classes that they define
...
h and others don't)
...

Above the #include line is a comment
...
Another way to comment,
which you can find a few lines later, is the standard C comment syntax
...
The message
can span many lines as needed, as shown in the typical commenting style below:

/*
* The C++ compiler can not see ANYthing I type here
* because I typed the symbol /* However, it can see my
* code again after I type the next line
...
You can insert as many
extra blank lines or "white space" as you'd like in order to make your program more
(or less) readable
...

The third line is one which appears in every program
...

The main() function is often of return type void
...
For now, just
accept that every program needs to have a main() function to tell it where to start, and it
should appear after your #include statements
...
The executed part of the program is

what's between the braces
...

Now that you have some idea of a very simple C++ program structure, here is a more
general program structure:
1) Comments-- It is conventional to including a few details about your program at the top
of the file, both for documentation and so that other programmers can better understand
your program
...

2) Header files-- As mentioned above, #include other files containing function definitions
that you will need
...
They are essentially new data types
that may contain functions for retrieving, setting or manipulating the objects to which they
belong
...

4) Member function definitions-- Classes usually contain functions, most of which will be
defined outside of the actual class definition
...

5) Other function declarations -- Functions not particular to any class and not #included
in a header file are declared next
...
Such
functions are known as "global" functions because, like global variables, they are visible
everywhere in the program
...

7) main()-- As in the "Hello World" example, main() must appear in every program
...

8) Function definitions-- It is your choice whether or not to define your functions when
you declare them
...


Problems



Problem : What is the purpose of the #include statement in a C++ program?

The #include statement tells the C++ preprocessor to insert the definitions of
variables, classes, and functions into the current file
...
h>, for
example, lets you use the cout and cin functions, and #include ...
To #include files that are

not standard with C++ (files you define yourself, for instance) you use quotation
marks instead of angle brackets
...
g
...
h"


Problem : Why should you comment your code?

Commenting is important for documenting your code
...



Problem : What is whitespace?

Whitespace is the composition of spaces, tabs, and newlines that the compiler
ignores when compiling your code
...



Problem : Why must every program have a main() function?

The main() function is where your program starts execution
...



Problem : What is a global variable?

A global variable is a variable that is declared outside of main() and other functions
and is visible everywhere in your program
...
The basic variable data
types which C++ variables can assume are: int(integers), char (characters)
and doubles (real decimals)
...
Here is an example of declaring a
variable:

int number_of_items;

Defining (or initializing) a variable is giving it a value
...
72168000517;

Of course, variables can be assigned values at a later time, too:

int trees, shrubs;
trees = 6;
shrubs = trees;

It is important to note that characters are represented by numbers in the computer, and
a char variable can be assigned a numerical value
...
Some escape sequences are:'\\' -- backslash '\'' -- single quotation
mark '\"' -- double quotation mark '\b' -- backspace '\n' -- new line '\r' -- carriage
return '\t' -- tab
A string is a sequence of characters ending in the null character (whose escape
sequence is '\0')
...
They are as follows:


unsigned char -- takes non-negative values twice as high as normal chars
...



long -- or long int, are like ints, but can take on much larger values
...




bool -- takes on either the value true or the value false
...
For instance, it
is generally considered stylistically poor to have constants without explanation, as in the
following:

float area = 3
...
1415 be confusing, but it is like that you will want to
use the same value elsewhere in your program
...
1415;
float area = PI * radius * radius;

This syntax replaces C's #define syntax for defining constants
...

Sometimes you may want to forget entirely that your variables are being represented by
numbers
...

This will work, but C++ lets you more easily create your own enumerated type as follows:

enum day_type {Sunday, Monday, Tuesday, Wednesday, Thursday, Friday,
Saturday};
day_type favorite_day;
favorite_day = Saturday;

The enum command lets you define a new data type and the (constant) values a variable
of this new data type can take on
...


Problems



Problem : Why are there different data types?

Different data types are used for different types of values
...
e
...
If the numbers require a broader range, then long integers, which
take up more space in memory, are better
...



Problem : Why use escape sequences?

Some characters cannot be represented by a symbol on the keyboard
...



Problem : What is the difference between a signed data type and
an unsigned data type?

Variables are usually signed, which means they can take on both positive ad negative
values
...



Problem : Why should you use constant variables?

Constant variables are good for constants that will be used repeatedly, as they are
clearer and allow for modification
...
7 and you later change your mind and want it equal to 2
...
If you just used the number, you would have to modify
the value 2
...



Problem : How are enumerated types useful?

Enumerated types are used to create new data types that have a finite range of
possible values
...



Title: GETTING STARTED IN C++
Description: Introduction and Summary Terms Summary and Analysis Introduction to C++ Programs Problems Data Types Problems