How do you declare an empty string?
string name = "";
How do you declare a vector of strings?
vector<string> myVector;
What data types can structs contain?
Any/all
If you are repeating the same thing in your code multiple times, what should you do?
Create a function
What is the difference between an integer and a double?
integer is only whole numbers, double can contain decimals
Demonstrate 2 ways to declare a string named class and initialize it with the value "ENGR101"
string class("ENGR101");
string class;
class = "ENGR101";
How do you clear a vector?
myVector.clear()
What should you do to the name of your struct when creating it?
Capitalize the first letter
Which function do you write the main part of your program in?
int main(){}
How do you declare a new filestream for the input file named "input.txt"?
ifstream file("input.txt");
How do you combine the following strings:
string a = "my";
string b = "name";
so that they read "my name"
string newString = a + " " + b;
How can you declare a vector of int's named numbers with the numbers 3,4,5,6 in one line?
vector<int> numbers{3, 4, 5, 6};
Create a struct Person with member variables name, age, and height
struct Person{
string name;
int age;
double height;
};
If you know the number of times you are going to do something, which type of loop should you use?
for
What return type should you use for a function that has no return value?
void
string mail = "email";
Replace the letter e with g
mail.replace(0,1,"g");
How can you initialize a vector of size 4 containing the character 'a' using one line of code?
vector<char> myVector(4, 'a');
What variable type does the .size() function produce? (ex. myVector.size())
size_t
Which code library do you need to include in order to use input/output filestreams? (use correct code syntax)
#include <fstream>
Write a for loop that would iterate through
vector<int> numbers
and print out each number. (your code shouldn't generate warnings)
for(size_t i = 0; i < numbers.size(); ++i){
cout << numbers.at(i);
}
What is wrong with this code?
struct Per{
string name;
};
int main(){
Per pNew;
cout << npew.name << endl;
}
The cout statement won't print anything since pNew is empty
How do you run a program after compiling it using this compile statement:
g++ -std=c++11 -Wall -pedantic myCode.cpp myFunctions.cpp -o myFuncCode
./myFuncCode
Write a function header for a function called calculator that takes in a string and a double and returns a double.
double calculator(string s, double x){}