Section One Flashcards

1
Q

What do you need to write C++

A

A text editor like notepad
A compiler like GCC to translate the code into a language that the computer will understand

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

What is an IDE

A

Integrated Development Environment

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

What compiler are you using

A

GCC from mysys2.org

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

What is a header file library?
Show an example of one.

A

include <iostream></iostream>

Allows us to work with input and output objects.

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

Make your program able to use names for objects and variables from the standard library

A

include <iostream></iostream>

using namespace std;

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

What function is always required in your code? What happens to the code inside of it?

A

int main() {

}

Code inside curly brackets is always executed.

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

What is an insertion operator?
Use it with an object to use hello world

A

int main() {
cout &laquo_space;“Hello World!”;
return 0;
}

&laquo_space;- insertion object

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

What does every statement end with?

A

;

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

How do you end the main function?

A

return 0

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

What is a computer program?

A

List of instructions to be executed by a computer.

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

What are the instructions that you give your computer called?

A

statements

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

Add the numbers 3 + 3

A

include <iostream></iostream>

using namespace std;

int main() {
cout &laquo_space;3 + 3;
return 0;
}

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

How do you insert a new line the popular way?

A

include <iostream></iostream>

\n - new line character that is an escape sequence

You can also do this

using namespace std;

int main() {
cout &laquo_space;“Hello World!” &laquo_space;“\n”;
cout &laquo_space;“I am learning C++”;
return 0;
}

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

Other than \n, what is another way to create a blank line?

A

include <iostream></iostream>

using namespace std;

int main() {
cout &laquo_space;“Hello World!” &laquo_space;endl;
cout &laquo_space;“I am learning C++”;
return 0;
}

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

How would you:
tab
insert a backslash
insert a double quote

A

\t

"

EXAMPLE
#include <iostream>
using namespace std;</iostream>

int main() {
cout &laquo_space;“They call him "Johnny".”;
return 0;
}

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

How do you make a comment?

A

include <iostream></iostream>

using namespace std;

int main() {
// This is a comment
cout &laquo_space;“Hello World!”;
return 0;
}

OR

cout &laquo_space;“Hello World!”; // This is a comment

17
Q

Create a multiline comment

A

include <iostream></iostream>

using namespace std;

int main() {
/* The code below will print the words Hello World!
to the screen, and it is amazing */
cout &laquo_space;“Hello World!”;
return 0;
}

18
Q

What are the 5 variable types

A

int
double - float
char - single character
string
bool

19
Q

Create a variable named myNum and give it the value of 15

Print to screen

A

include <iostream></iostream>

using namespace std;

int main() {
int myNum = 15;
cout &laquo_space;myNum;
return 0;
}

OR ASSIGN THE VALUE LATER

int myNum;
myNum = 15;
cout &laquo_space;myNum;

20
Q

Create a variable and use it in a string to output the statement:
‘I am 34 years old’

A

include <iostream></iostream>

using namespace std;

int main() {
int myAge = 35;
cout &laquo_space;“I am “ &laquo_space;myAge &laquo_space;” years old.”;
return 0;
}

21
Q

Declare several integer variables

A

int x = 5, y = 6, z = 50;

22
Q

Create 3 integers and give them all the same value

A

include <iostream></iostream>

using namespace std;

int main() {
int x, y, z;
x = y = z = 50;
cout &laquo_space;x + y + z;
return 0;
}

23
Q

What are identifiers?

A

Variables must be identified with unique names

So basically variable names

24
Q

What do variables have to start with and what can they contain?

A

Names can contain letters, digits and underscores
Names must begin with a letter or an underscore (_)

25
Q

What is a constant?
Make one

A

Read-only variable. It can’t be changed.

They HAVE TO contain a variable

const int myNum = 15;

26
Q

Put user input into a variable and print it

You’ll need to use an extraction operator

A

int x;
cout &laquo_space;“Type a number: “; // Type a number and press enter
cin&raquo_space; x; // Get user input from the keyboard
cout &laquo_space;“Your number is: “ &laquo_space;x; // Display the input value

27
Q

Using user input, create a calculator that takes two numbers and adds them together

A

int x, y;
int sum;
cout &laquo_space;“Type a number: “;
cin&raquo_space; x;
cout &laquo_space;“Type another number: “;
cin&raquo_space; y;
sum = x + y;
cout &laquo_space;“Sum is: “ &laquo_space;sum;

28
Q

What are the sizes of the below data types:
bool
char
int
double

A

bool - 1 byte

char - 1 byte

int - 2 or 4 bytes

double 8 bytes

29
Q

Difference between a float and a double

A

The precision of a floating point value indicates how many digits the value can have after the decimal point. The precision of float is only six or seven decimal digits, while double variables have a precision of about 15 digits. Therefore it is safer to use double for most calculations.

30
Q

Code a boolean variable

A

bool isCodingFun = true;
bool isFishTasty = false;
cout &laquo_space;isCodingFun; // Outputs 1 (true)
cout &laquo_space;isFishTasty; // Outputs 0 (false)

31
Q

Should you put a single character in single or double quotes?

32
Q

Do you need to include a certain library to use strings?

A

// Include the string library
#include <string></string>

// Create a string variable
string greeting = “Hello”;

// Output string value
cout &laquo_space;greeting;

33
Q

Using variables
create a program that takes
amount = 50
cost per item = 9.99
total cost = multiply here
currency = $ - Just make the dollar sign in the variable to use in your program.

A

include <iostream></iostream>

using namespace std;

int main() {
// Create variables of different data types
int items = 50;
double cost_per_item = 9.99;
double total_cost = items * cost_per_item;
char currency = ‘$’;

// Print variables
cout &laquo_space;“Number of items: “ &laquo_space;items &laquo_space;“\n”;
cout &laquo_space;“Cost per item: “ &laquo_space;cost_per_item &laquo_space;”” &laquo_space;currency &laquo_space;“\n”;
cout &laquo_space;“Total cost = “ &laquo_space;total_cost &laquo_space;”” &laquo_space;currency &laquo_space;“\n”;

return 0;
}

34
Q

How do you increase a number by one?

A

int x = 10;
++x;