C++ General Flashcards

1
Q

What are the 6 types of Operations in c++?

  • Definition
A
  1. Arithmetic
  2. Assignment
  3. Logical
  4. Relational
  5. bitwise
  6. Miscellaneous
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the 8 Punctuators in C++ ?

A
  1. // (Double Slash)
  2. # (Pound Sign)
  3. < > (Open/Close Brackets)
  4. ( ) (Open/Close Parenthesis)
  5. { } (Open/Close Brace)
  6. ” “ (Open/Close Quotation Marks)
  7. ; (Semicolon)
  8. : (Colon)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Explain the Double Slash ( // )

A

The double slash means the beginning of a comment

// Coding is Challenging

  • (The compiler will ignore anything after the double slash)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Explain Open/Close Brackets ( < > )

A

Include<…>

Encloses File name in #Include

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Explain the Pound Sign ( # )

A

Include

The pound sign ( # ) means the beginning of a preprocessor directive

  • Directs the preprocessor to include the file called “Iostream” during the compilling process
  • “Iostream” is also known as the header file
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are the parts of a C++ Program

A
  1. Comment
  2. Preprocessor Directive
  3. Which Namespace to use
  4. Begin a Function (main) with open/closed brace
  5. Output Statement
  6. Send 0, to operating system
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Explain “Comment”

A
  • Comment uses “//” (Slashes)
  • Marks the beginning of a comment
  • The compiler ignores everything from the Slashes to the end of the line
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Explain Preprocessor directive

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Explain cout

A

cout displays output on the computer screen

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the sytax of “cout”

  • Example
A
  1. Declare cout (Declare you want to display output)
  2. Use two open brackets << to send the output
  3. Use parenthesis and write what you want to send betweem them
  4. Separate more than one item with more brackets
  5. Use a semicolon to mark the end of the statement
    - cout << “Coding is stressful” ;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Explain “endl”

A

endl starts a new line of output

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the syntax of “endl”

A
  1. Begin with two open braces
  2. Write it before the end of the output code
  3. Punctuate with a semicolon to mark the end of the statement

cout << “Coding is stressfull” << endl;

return 0;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Explain “/n”

A

The escape sequence “/n” starts a new line of output

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the syntax of /n

A
  1. Declare the escape sequence within the end of the output string

cout << “Coding is stressfull /n” ;

return 0;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Define Variables

A

A variable is a named storage location in the computer’s memory for holding a piece of data.

17
Q

Define “literals”

A

Literals are the constant values that are assigned to variables

18
Q

What is the syntax of a “integer variable”?

A
  1. Create a variable definition

int apples;

  1. Create a variable assignment

apples = 12;

*3.* Display the variable

cout << “We sold” << apples << “Apples” << endl;

return 0;

* “We sold 12 Apples”

19
Q

What is the syntax of a “character variable”?

A
  1. Create a variable definition

char letter;

  1. Create a variable assignment enclosed in single quotations

letter = ‘c’ ;

  1. Display the character variable

cout << “The answer is letter” << letter << ‘/n’ ;

return 0;

* The answer is letter c

20
Q

What is the syntax of a “character string”

A

Include

  1. Create a string header file
  1. Define string type variables

string firstname, last name;

  1. Assign string type variables

firstname = Cristian;

lastname = Colin;

  1. Display the character variable *scroll down*

cout << “My first name is” << firstname << endl;

return 0;

21
Q

Explain cin

A

cin is used to read input from the keyboard

  • Whole numbers, Fractional, letters
22
Q

What is the syntax of cin

A
  1. Create a integer variable for the input and output
  2. Display a prompt using cout asking for an input value
  3. use cinn >> variable;
  4. Create an equation for the output
  5. Display output with cout << the output is << output << endl;

return 0;

23
Q

entering multiple values with cin

A

entering

24
Q

Writing operations for power functions

A

pow (s, 2) ;

  • Raises “s” to the second power
25
Q

How do you write multiple assignments?

A

x = y = z = 5

  • The assignment operator associates from right to left
26
Q

Formatting output

A
  • Requires Iomanip header file
  • control size, number of digits, position, of output

-

27
Q

setw(x)

A
  • prints variable output in a field at least x spaces wide

cout << set(6) << number1 << set(6) << number2 << set 6 << number3 << endl;

return 0;