- (100 points)
- (20 points)
What will be printed out when the application
a_01.cpp is executed?
- (80 points)
Do the necessary abstractions to decompose the given
a_01.cpp, so that,
the functional abstraction with separate, individual
functions are used to
the fullest extent with all the details are
hidden in functions while main is used
to invoke all the functions in the logical order.
// a_01.cpp
#include <iostream>
#include <vector>
#include <string>
using namespace std;
const string B = "10";
int main(int argc, char* argv[]) {
// init
vector<string> given;
given.push_back("01010101");
given.push_back("11000011");
given.push_back("10011000");
given.push_back("10010111");
// compute
vector< vector<int> > computed;
int n = given.size();
for(int i=0; i<n; ++i) {
string t = given.at(i);
// count
vector<int> counts(2,0);
char b = B.at(0);
int l = t.length();
for(int j=0; j<l; ++j)
if(t.at(j)==b) ++counts.at(0);
else ++counts.at(1);
computed.push_back(counts);
}
// output
int m = computed.size();
cout << endl;
for(int i=0; i<m; ++i) {
vector<int> v = computed.at(i);
cout << v.at(0) << endl;
}
cout << endl;
// output
for(int i=0; i<m; ++i) {
vector<int> v = computed.at(i);
cout << v.at(1) << endl;
}
}
4
4
3
5
4
4
5
3