I recently took c++ multiple choice test and below questions are always confusing me. Any inputs?
Question1:
which of lines of code substituted for occurences of **A** in below code, to take sentence in form of string and create a vector of single words(tokens)?
class Cart {
bool bCountValid;
int fruitCount;
staticint apples;
staticint oranges;
public:
Cart() : fruitCount(0), bCountValid(false) {}
void addApples(int a) { apples += 1; bCountValid = false;}
void addOranges(int o) { oranges += o; bCountValid = false;}
int getItemCount() const {
if(!bCountValid) { fruitCount = apples + oranges; bCountValid = true; }
return fruitCount;
}
};
int Cart::apples = 0;
int Cart::oranges = 0;
int main(int argc, char**argv)
{
Cart const checkoutPerson;
Cart shopper;
shopper.addApples(2);
shopper.addOranges(7);
int total = checkoutPerson.getItemCount();
}
1)Remove const qualifier from member function getItemCount()
2)Declare the shopper object to be of type Cart const rather than of type Cart.
3)Make members apples and oranges mutable
4)Make members apples and oranges non-static members
5)Make members bCountValid and fruitCount mutable
Question3:
which of following are valid ways to create type alias in c++?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
1)typedefint intAlias;
intAlias count;
2)typedef std::vector<T> vec;
vec<double> weights;
3)template<typename T> using myGenric = T;
myGenric<int> age;
4)typedef T genricAlias<T>;
genricAlias<int> population;
5)template<class T> using vec = std::vector<T>;
vec<float> incomes;
Question4:
which of following declarations is a valid way of defining template alias in c++?
1 2 3 4
1)typedeftemplate<class T> std::unique_ptr<T, std::function<void (T*) >> UP;
2)typename UP = std::unique_ptr<T, std::function< void (T*) >> UP;
3)template<class T> using UP = std::unique_ptr<T, std::function<void (T*) >>;
4)using UP = std::unique_ptr<T, std::function< void (T*) >>;
This has nothing to do with being a C++ expert. This has everything to do with the effort you put into it.
This is a “which of my students was paying attention” kind of exam. In other words, this tests whether or not you have been bothering to learn the course material.
Yes, YOU, as the student, are expected to pay attention and study along enough to follow the very most basic definitions relating to C++ language concepts. Having not done that, you are now lost and confused.
Unfortunately, your modus operandi on this forum as been to repeatedly ask us to do your thinking for you. You cannot learn that way. You only cheat yourself.
And I’ve already spent too much time on this answer...