Coding Exam Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

Declare a comment with your student number.

A

//01029384

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

Declare a variable for storing the number of students in a lecture.

A

int numOfStudents;

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

Declare a variable for storing the name of car.

A

std::string carName;

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

Declare a variable for storing someone’s height.

A

float height;

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

Declare a variable for storing the state of a door lock.

A

bool doorState;

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

Write statement to print ‘Hello Sam’.

A
//Hello sam
    std::cout << "Hello sam";
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Write statement to print the value stored in an integer variable called age.

A
//The value stored in a integer variable called age
    std::cout << age;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Write statement to print the value of a variable called time followed by a new line but proceeded by a tab space.

A
//The value of a variable called time followed by a new line but proceeded by a tab space
    std::cout << "\t" << time << "\n";
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Write statement to declare and read a integer number from the QWERTY keyboard

A

int num;

std::cin&raquo_space; num;

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

Write statement to declare and read a float from the QWERTY keyboard

A

float num;

std::cin&raquo_space; num;

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

Write statement to declare and read a string from the QWERTY keyboard

A

std: :string name;

std: :cin&raquo_space; name;

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

Declare a constant value called twoPi with the value 6.28318

A

const float twoPi = 6.28318;

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

Declare a constant value called name with your name

A

const std::string name = “dave”;

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

Write the following in C++ code: area = 2piR(squared)

A

const float twoPi = 6.28318;
float r = 1;
float area = twoPi * pow(r, 2);

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

Write an if statement that prints “lift-off” if a variable named time reaches 0.

A

if (time == 0) {
std::cout &laquo_space;“Lift-off”;
}

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

Write an if…else statement that will print “light” if a variable named weight has a value less than 50 and print “heavy” otherwise

A
if (weight < 50) {
	std::cout << "light \n";
}
else {
	std::cout << "heavy \n";
}
17
Q

Write a switch case for all the days of the week, whereby the input is a number representing the day and each case should print the day in text form.

A
int day;
    switch (day) {
        case 0: // same as saying if (day == 0) 
            std::cout << "Monday \n";
            break;
        case 1: // same as saying else if (day == 1) 
            std::cout << "Tuesday \n";
            break;
        case 2:
            std::cout << "Wednesday \n";
            break;
        case 3:
            std::cout << "Thursday \n";
            break;
        case 4:
            std::cout << "Friday \n";
            break;
        default:
            // error handling for values that don't match
            break;
    }
18
Q

Write a function declaration for a function called bang, that takes no arguments and does not return anything.

A

void bang ();

19
Q

Write a function declaration for a function called square, that takes a single float argument and returns a float.

A

float square (float x);

20
Q

Write a function declaration for a function called printVector, that takes a single int vector as an argument and does not return anything.

A

void printVector (std::vector vector);

21
Q

Write a function definition for a function called bang, that takes no argument and does not return anything.

A

void IAP::bang ()
{

}

22
Q

Write a function definition for a function called square, that takes a single float argument and returns a float.

A

float IAP::square (float x)
{

}

23
Q

Write a function definition for function called printVector, that takes a single int vector as an argument and does not return anything

A

void IAP::printVector (std::vector vector)
{

}

24
Q

Declare an array of an appropriate type that could store

30 MIDI note numbers.

A

std::array midiNotes;

25
Q

Declare a vector of an appropriate type that could store amplitude values.

A

std::vector amps;

26
Q

Write a statement that stores the number 15 in the 2nd index of an array called numbers.

A

std::array numbers;

numbers[1] = 15;

27
Q

Write a statement that appends the value 60

to a vector called noteList.

A

std::vector noteList;

noteList.push_back(60);

28
Q

Write a for loop that starts at 0 and goes up to and including 10.

A

for (int i = 0; i <= 10; i++)

29
Q

Write a for loop that starts at 5 and goes down to and including -5

A

for (int i = 5; i >= -5; i–)

30
Q

Copy the value of a string called nameA to another string called nameB and then append the value of a string called nameC to the string called nameB.

A

std::string stringA;
std::string stringB;
std::string stringC;
stringB = stringA;

stringB += StringC;
31
Q
Class (1): Declare a class called MIDINote that has 3 integer member variables called
 - Status, data1, data2
A
class MIDINote {
public:
    int status, data1, data2;
}
32
Q

Class (2): Declare an instance of MIDINote

A

MidiNote mNote;

33
Q

Class (3): Set each of MIDINote’s member variables to

144, 60, 127

A

mNote.Status = 144;
mNote.data1 = 60;
mNote.data2 = 127;

34
Q
Class(4): Add a class method called print that prints all
of the class’ member variables
A
void print ()
    {
        std::cout << "Status: " << status << "Data 1: " << data1 << "Data 2: " << data2 << "\n";
    }
35
Q

Write the number 57 in hex.

A

0x39

36
Q

Write the number 57 in binary.

A

0011 1001

37
Q

How many bits are needed to store the number 502

A

9 bits

38
Q

How many bits are needed to store the number 255

A

8 bits

39
Q

How many bits are needed to store the number 16

A

5 bits