COP-3014 Study Guide - Final Guide: Switch Statement, Delimiter, Unary Operation
COP3014 FINAL REVIEW
BY: JORDAN DEBENEDICTIS
AND
ILIANA SANDOVAL
• Basic C++ Syntax
– Writing a basic C++ program stub: including required libraries, adding namespaces and
writing the main function.
● #include <iostream>
● Libraries are pre-compiled code available to the programmer to perform common
tasks
● Some libraries are standard, others are specific (string, cstring, etc.)
● using namespace std;
● The using statement tells the compiler that all uses of these names (cout, cin, etc)
will come from the ”standard” name
● function: a subprogram. a section of a program performing a specific task. Every
function body is defined inside a block.
● For a C++ executable, exactly one function called main()
● Can consist of multiple files and typically use libraries.
– Simple statements - syntax.
● Statements: smallest complete executable unit of a program.
● Simple statements all end with a semicolon
○ cout<<”hello”<<end;
find more resources at oneclass.com
find more resources at oneclass.com
– Comments
● Comments are ignored by the compiler
● Meant to document programs
● Line comments use two slashes (//) blocks use (/*)
● Line comments
○ //this is a line comment//
● Block comments
○ /* This is a comment.
It can span multiple lines */
– Reserved words, literals and escape sequences.
● Reserved words (keywords) cannot be used as identifiers
● Keywords: Words with special meaning to the compiler.
○ int, char, using, main, etc.
– Style guidelines
• Primitive Data types, variables, operators, and sequential execution.
● Primitive data types:
○ bool: has two possible values, true or false
○ integer types:
■ char - 1 byte on most systems.
● Typically used for representing characters
● Stored with an integer code underneath (ASCII on most computers
today)
■ short - (usually at least 2 bytes)
find more resources at oneclass.com
find more resources at oneclass.com
■ int - (4 bytes on most systems)
■ long - (usually 4 or more bytes)
■ The integer types have regular and unsigned versions
○ floating point types - for storage of decimal numbers (i.e. a fractional part after
the decimal)
■ float
■ double
■ long double
– Naming, declaring and initializing variables.
● Declaring a variable is to tell the computer it exists and to reserve memory for it
○ int numStudents, double weight, char letter
● Initializing variables is to load a value into it for the first time
○ numStudents =10;
– Primitive data types
● Atomic data types are the built-in types defined by the C++ language
● There are 4 (boolean, integers, characters, and floats)
– Type Conversions - implicit and explicit.
● implicit type conversion, where the compiler automatically
transforms one fundamental data type into another,
○
find more resources at oneclass.com
find more resources at oneclass.com
Document Summary
Writing a basic c++ program stub: including required libraries, adding namespaces and writing the main function. Libraries are pre-compiled code available to the programmer to perform common tasks. Some libraries are standard, others are specific (string, cstring, etc. ) using namespace std; The using statement tells the compiler that all uses of these names (cout, cin, etc) will come from the standard name. Every function body is defined inside a block. For a c++ executable, exactly one function called main() Can consist of multiple files and typically use libraries. Statements: smallest complete executable unit of a program. Simple statements all end with a semicolon. Line comments use two slashes (//) blocks use (/*) Reserved words (keywords) cannot be used as identifiers. Keywords: words with special meaning to the compiler. int, char, using, main, etc. Style guidelines: primitive data types, variables, operators, and sequential execution. Bool: has two possible values, true or false integer types: Char - 1 byte on most systems.