Lecture 2 Flashcards
Top-level Structure of Programs, Data Representation, Variables
A C++ program is a collection of?
Functions
What type of function is always in a C++ program?
main() which is always executed first
What are the other functions beside main() called and when are they executed?
Other functions in the program are
subprograms and are not executed until they
are called
What is a statement and what does this end in?
An instruction that ends with a semi-colon
What is a block?
Any section of code which is surrounded by curly brackets is a block
e.g. A block of 4 statements
{
cout «“A fraction: “«5.0/8.0 «endl;
cout «“Big # : “«_space;7000.0*7000.0«endl;
cout «8 + 5 «” is the sum of 8 & 5\n”;
cout «_space;“Hello world”;
}
What are the types of information a computer uses?
Simple (needs little or no effort to use)
* To hold whole numbers (integers)
* To hold numbers with fractions (float and double)
* To hold individual characters (char)
Complex (needs a little more work to use)
* Strings
* cin and cout
What is the difference between char(acter) and string?
Char is single characters, string is a lot of characters
What does a C++ program normally need to do?
- Reserving and labelling some space to store
information - Getting information like int or string into the space you reserved
- Doing something (operate on) with the information (int, float, double, char or string)
- Displaying results
What is constant?
A fixed value represented by something e.g. π
What is a variable
A value that can change
What is a literal?
A fixed value that represents itself, e.g. 2 or 7
What can you categorise information as?
- constant
- variable
- literal
How does information of variable, constant and literals get into the computer?
We enter values of literals and constants directly into code but for constants we instruct the computer to reserve space for a constant.
We instruct the computer to reserve space for a variable. We have a choice on how we enter
values of variables. We can enter values directly in code or can be set interactively with a user.
What are the named areas of memory called?
Variables and Constants
What is a declaration?
When the computer is instructed to
reserve space for information and at the same time tell the computer the name that will be used to refer to that bit of information