Coding Exam Flashcards
Declare a comment with your student number.
//01029384
Declare a variable for storing the number of students in a lecture.
int numOfStudents;
Declare a variable for storing the name of car.
std::string carName;
Declare a variable for storing someone’s height.
float height;
Declare a variable for storing the state of a door lock.
bool doorState;
Write statement to print ‘Hello Sam’.
//Hello sam std::cout << "Hello sam";
Write statement to print the value stored in an integer variable called age.
//The value stored in a integer variable called age std::cout << age;
Write statement to print the value of a variable called time followed by a new line but proceeded by a tab space.
//The value of a variable called time followed by a new line but proceeded by a tab space std::cout << "\t" << time << "\n";
Write statement to declare and read a integer number from the QWERTY keyboard
int num;
std::cin»_space; num;
Write statement to declare and read a float from the QWERTY keyboard
float num;
std::cin»_space; num;
Write statement to declare and read a string from the QWERTY keyboard
std: :string name;
std: :cin»_space; name;
Declare a constant value called twoPi with the value 6.28318
const float twoPi = 6.28318;
Declare a constant value called name with your name
const std::string name = “dave”;
Write the following in C++ code: area = 2piR(squared)
const float twoPi = 6.28318;
float r = 1;
float area = twoPi * pow(r, 2);
Write an if statement that prints “lift-off” if a variable named time reaches 0.
if (time == 0) {
std::cout «_space;“Lift-off”;
}