[CPP] Chapter 8 Quiz/Assessment

 Question 1

/ 1 pts

What will happen when you attempt to compile and run the following code?

#include <iostream>
using namespace std;
int main()
{
    cout<<127<<", ";
    cout.setf(ios::hex);//LINE I
    cout<<127<<", ";
    cout.setf (ios::showbase );  //LINE II
    cout<<127<<", ";
    return 0;
}
  
  
  
  
  
  
  
 
Question 2
/ 1 pts

What will happen when you attempt to compile and run the following code?

#include <iostream>
using namespace std;
int main()
{
    cout<<127<<", ";
    cout.setf(ios::hex);//LINE I
    cout<<127<<", ";
    cout.setf (ios::showbase, ios::basefield );  //LINE II
    cout<<127<<", ";
    return 0;
}
  
  
  
  
  
  
  
 
Question 3
/ 1 pts

What will happen when you attempt to compile and run the following code?

#include <iostream>
using namespace std;
int main()
{
    cout<<127<<", ";
    cout.setf(ios::hex, ios::basefield);//LINE I
    cout<<127<<", ";
    cout.setf (ios::showbase);  //LINE II
    cout<<127<<", ";
    return 0;
}
  
  
  
  
  
  
  
 
Question 4
/ 1 pts

What will happen when you attempt to compile and run the following code?

#include <iostream>
using namespace std;
int main()
{
    cout<<127<<", ";
    cout.setf(ios::hex, ios::basefield);
    cout.setf (ios::showbase);  //LINE I
    cout<<127<<", ";
    cout.unsetf(ios::showbase);  //LINE II
    cout<<127<<", ";
    return 0;
}
  
  
  
  
  
  
  
 
Question 5
/ 1 pts

What will happen when you attempt to compile and run the following code?

#include <iostream>
using namespace std;
int main()
{
cout<<127<<", ";
cout.setf(ios::oct, ios::basefield);
cout.setf (ios::showbase); //LINE I
cout<<127<<", ";
cout.unsetf(ios::showbase); //LINE II
cout<<127<<", ";
return 0;
}
  
  
  
  
  
  
  
 
Question 6
/ 1 pts

What will happen when you attempt to compile and run the following code?

#include <iostream>
using namespace std;
int main()
{
    cout<<127.45<<", ";
    cout.setf(ios::hex, ios::basefield);
    cout.setf (ios::showbase);  //LINE I
    cout<<127.45<<", ";
    cout.unsetf(ios::showbase);  //LINE II
    cout<<127.45<<", ";
    return 0;
}
  
  
  
  
  
  
  
 
Question 7
/ 1 pts

What will happen when you attempt to compile and run the following code?

#include <iostream>
using namespace std;
int main()
{
    cout<<127.45<<", ";
    cout.setf(ios::hex, ios::basefield);
    cout.setf (ios::showbase);  //LINE I
    cout<<127.45<<", ";
    cout.setf(ios::noshowbase);  //LINE II
    cout<<127.45<<", ";
    return 0;
}
  
  
  
  
  
  
  
 
Question 8
/ 1 pts

What will happen when you attempt to compile and run the following code?

#include <iostream>
using namespace std;
int main()
{
    cout<<127<<", ";
    cout.setf(ios::hex, ios::basefield);
    cout.setf (ios::showbase);  //LINE I
    cout<<127<<", ";
    cout.unsetf(ios::showbase);  
    cout<<std::showbase<<127<<", ";//LINE II
    return 0;
}
  
  
  
  
  
  
  
 
Question 9
/ 1 pts

What will happen when you attempt to compile and run the following code?

#include <iostream>
using namespace std;
int main()
{
    cout<<false<<", "; //LINE I
    cout<<boolalpha<<", ";//LINE II
    cout<<true<<", ";
    return 0;
}
  
  
  
  
  
  
  
 
Question 10
/ 1 pts

What will happen when you attempt to compile and run the following code?

#include <iostream>
using namespace std;
int main()
{
    double goodpi=3.1415;
    double badpi = 3.2;
    cout<<goodpi<<", ";
    cout<<badpi<<", ";
    cout.setf(ios_base::showpoint);//LINE I
    cout<<goodpi<<", "; //LINE II
    cout<<badpi<<", ";
    return 0;
}
  
  
  
  
  
  
  
 
Question 11
/ 1 pts

What will happen when you attempt to compile and run the following code?

#include <iomanip>
#include <iostream>
using namespace std;
int main()
{
    double goodpi=3.1415;
    double badpi = 3.2;
    cout<<goodpi<<", ";
    cout<<badpi<<", ";
    cout<<setprecision(3);//LINE I
    cout<<goodpi<<", "; //LINE II
    cout<<badpi<<", ";
    return 0;
}
  
  
  
  
  
  
  
 
Question 12
/ 1 pts

What will happen when you attempt to compile and run the following code?

#include <iomanip>
#include <iostream>
using namespace std;
int main()
{
    double goodpi=3.1415;
    double badpi = 3.2;
    cout<<goodpi<<", ";
    cout<<badpi<<", ";
    cout<<setprecision();//LINE I
    cout<<goodpi<<", "; //LINE II
    cout<<badpi<<", ";
    return 0;
}
  
  
  
  
  
  
  
 
Question 13
/ 1 pts

What will happen when you attempt to compile and run the following code?

#include <iomanip>
#include <iostream>
using namespace std;
int main()
{
    double goodpi=3.1415;
    double badpi = 3.2;
    cout<<goodpi<<", ";
    cout<<fixed;
    cout<<badpi<<", ";
    cout<<setprecision(3);//LINE I
    cout<<goodpi<<", "; //LINE II
    cout.unsetf(ios::floatfield);
    cout<<badpi<<", ";
    return 0;
}
  
  
  
  
  
  
  
 
Question 14
/ 1 pts

What will happen when you attempt to compile and run the following code?

#include <iomanip>
#include <iostream>
using namespace std;
int main()
{
    double goodpi=3.1415;
    double badpi = 3.2;
    cout<<goodpi<<", ";
    cout<<scientific;//LINE I
    cout<<setprecision(3);//LINE II
    cout<<goodpi<<", ";
    cout.unsetf(ios::floatfield);
    cout<<badpi<<", ";
    return 0;
}
  
  
  
  
  
  
  
 
Question 15
/ 1 pts

What will happen when you attempt to compile and run the following code, assuming you enter the following sequence: 9 8 7<enter> ?

#include <iostream>
using namespace std;
int main ()
{
    int c1, c2, c3;
    cin >> c1 >> c2 >> c3;
    cout << c3 << ", " << c1 << ", " << c2 << ", " << endl;
    return 0;
}
  
  
  
  
 
IncorrectIncorrectQuestion 16
/ 1 pts

What will happen when you attempt to compile and run the following code, assuming that you will enter the following sequence: 9 8 7<enter>?

#include <iostream>
#include <string>
using namespace std;
int main ()
{
    string s;
    cin >> s; //LINE I
    cout << s << ", " << s << ", " << endl; //LINE II
    return 0;
}
  
  
  
  
  
  
  
 
IncorrectIncorrectQuestion 17
/ 1 pts

What will happen when you attempt to compile and run the following code, assuming that you will enter the following sequence: 9 8 a<enter>??

#include <iostream>
#include <string>
using namespace std;
int main ()
{
    string s;
    getline(cin, s); //LINE I
    cout << s << ", " << s << ", " << endl; //LINE II
    return 0;
}
  
  
  
  
  
  
  
 
Question 18
/ 1 pts

What will happen when you attempt to compile and run the following code, assuming that you will enter the following sequence: 7 8 9<enter>?

#include <iostream>
#include <string>
using namespace std;
int main ()
{
    string s;
    getline(s); //LINE I
    cout << s << ", " << s << ", " << endl; //LINE II
    return 0;
}
  
  
  
  
  
  
  
 
Question 19
/ 1 pts

What will happen when you attempt to compile and run the following code, assuming that you will enter the following sequence: 9.9 8.8 7.7<enter>?

#include <iostream>
using namespace std;
int main ()
{
    double c1, c2, c3;
    cin >> c1 >> c2 >> c3;
    cout << c3 << ", " << c1 << ", " << c2 << ", " << endl;
    return 0;
}
  
  
  
  
 
Question 20
/ 1 pts

What will happen when you attempt to compile and run the following code, assuming that you will enter the following sequence: true false 1<enter>?

#include <iostream>
using namespace std;
int main ()
{
    bool c1, c2, c3;
    cin >> boolalpha >> c1 >> c2 >> c3;
    cout << boolalpha << c3 << ", " << c1 << ", " << c2 << ", " << endl;//LINE I
    return 0;
}
  
  
  
  
  
  
 
IncorrectIncorrectQuestion 21
/ 1 pts

What will happen when you attempt to compile and run the following code, assuming that you will enter the following sequence: r e w qw q<enter>?

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
void printer(string i) {
    cout << i << ", ";
}
int main ()
{
    vector<string> v1;
    string s;
    do
    {
        cin >> s;
        v1.push_back(s);//LINE I
    }
    while (s != "q" && cin.good());//LINE II
    for_each(v1.begin(), v1.end(), printer);
    return 0;
}
  
  
  
  
  
  
  
 
Question 22
/ 1 pts

What will happen when you attempt to compile and run the following code, assuming that you will enter the following sequence: 7 8 9<enter>?

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
void printer(int i) {
    cout << i << ", ";
}
int main ()
{
    vector<int> v1;
    int i;
    do
    {
        cin >> i;
        v1.push_back(i);//LINE I
    }
    while (i != 9 && !cin.bad());//LINE II
    for_each(v1.begin(), v1.end(), printer);
    return 0;
}
  
  
  
  
  
  
  
 
IncorrectIncorrectQuestion 23
/ 1 pts

What will happen when you attempt to compile and run the following code, assuming that you will enter the following sequence: 255 127<enter>?

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <sstream>
using namespace std;
void printer(int i) {
    cout << setw(4) << i << ", ";
}
int main ()
{
    string s;
    getline(cin, s);
    stringstream input(s);//LINE I
    vector<int> v1;
    int i;
    do
    {
        input >> hex >> i;
        v1.push_back(i);//LINE II
    }
    while (!input.fail());
    for_each(v1.begin(), v1.end(), printer);
    return 0;
}
  
  
  
  
  
  
  
  
  
 
IncorrectIncorrectQuestion 24
/ 1 pts

What will happen when you attempt to compile and run the following code, assuming that the file input.txt contains the following sequence: t r e?

Note: spaces are important.

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <fstream>
using namespace std;
void printer(char c) {
    cout << setw(2) << c << ", ";
}
int main ()
{
    ifstream inputfile("input.txt");
    vector<char> v1;
    char c;
    do
    {
        inputfile>>c;//LINE I
        v1.push_back(c);
    }
    while (inputfile.good());//LINE II
    inputfile.close();
    for_each(v1.begin(), v1.end(), printer);
    return 0;
}
  
  
  
  
  
  
  
  
 
Question 25
/ 1 pts

What will happen when you attempt to compile and run the following code?

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <fstream>
using namespace std;
void printer(int i) {
    cout << setw(2) << i << ", ";
}
int main ()
{
    int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5 };
    vector<int> v1(mynumbers, mynumbers + 7);
    fstream outfile("output.txt", ios::trunc|ios::out);
    int i ;
    while (outfile.good());//LINE I
    {
        outfile>>i;//LINE II
        v1.push_back(i);
    }
    outfile.close();
    for_each(v1.begin(), v1.end(), printer);
    outfile.close();   outfile.open("output.txt");
    return 0;
}
  
  
  
  
  
  
  
  
 
PartialPartialQuestion 26
0.5 / 1 pts

What will happen when you attempt to compile and run the following code? Choose all that apply.

#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
using namespace std;
class Pocket {
    int value;
public:
    Pocket(int value):value(value){}
    operator int() const
    {return getValue();}//LINE I
    int getValue() const
    { return value; }  
    bool operator < (const Pocket & _Right) const
    { return value < _Right.value; }
};
ostream & operator <<(ostream & stream, const Pocket & pocket)
{
    stream << pocket.getValue();
    return stream;
}
void printer(int i) {
    cout << i << ", ";
}
int main () {
    int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5 };
    vector<Pocket> v1(mynumbers, mynumbers + 7);
    fstream outfile("output.txt", ios::trunc|ios::out);
    for_each(v1.begin(), v1.end(), printer);
    outfile.close();
    outfile.open("output.txt");
    while( outfile.good())   //LINE II
    {
        int i;
        outfile>>i;
    }
    outfile.close();
    return 0;
}