| linker | compiler | ls | cd | constructor |
| g++ | vector | array | struct | class |
| private | protected | public | substr | find |
| make | makefile | argc | argv | vi |
| mutator method | accessor method | header file | object file | executable |
class Person {
string firstname;
string lastname;
string address;
}
| (a) | (b) |
Person::Person(string fn, string ln, string addr) {
firstname = fn;
lastname = ln;
address = addr;
}
|
Person::Person(string fn, string ln, string addr):
firstname(fn), lastname(ln), address(addr) {}
|
|---|
vector<int> v;
int i;
int originalSize;
// (1) resize the vector
originalSize = v.size();
v.resize(v.size() + 3);
// (2) shift the existing entries to the right
for (i = 0; i < originalSize; i++) {
v[i+3] = v[i];
}
// (3) fill the vacated entries with 0's
for (i = 0; i < 3; i++) {
v[i] = 0;
}
Suppose that v contains the contents:
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
|---|---|---|---|---|---|---|---|
| 10 | 20 | 30 | 40 | 50 | 60 | 70 | 80 |
The code fragment is intended to produce the following result:
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 10 | 20 | 30 | 40 | 50 | 60 | 70 | 80 |
The code fragment as written does not achieve its intended purpose. Answer the following questions:
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
h(key) = key % 11
| Separate Chaining | Quadratic Probing | |
|---|---|---|
| 0 | ||
| 1 | ||
| 2 | ||
| 3 | ||
| 4 | ||
| 5 | ||
| 6 | ||
| 7 | ||
| 8 | ||
| 9 | ||
| 10 |
| key | quadratic probing |
|---|---|
| 32 | |
| 12 | |
| 48 | |
| 19 | |
| 52 | |
| 58 | |
| 30 | |
| 25 |
char animal; // the letter of the most recently collected animal
int totalPoints; // the total number of points earned thus far
Write a single C++ statement that will convert the character stored in animal to the correct point value and add that point value to totalPoints
string name; double salary; int age;
#include <iostream>
#include <sstream>
using namespace std;
int main() {
istringstream buffer;
int num;
double num1;
int sum1 = 0;
double sum2 = 0;
string input;
while (cin >> input) {
buffer.clear();
buffer.str(input);
if (buffer >> num1) {
if (input.find('.') == string::npos) {
buffer.clear();
buffer.str(input);
buffer >> num;
sum1 += num;
}
else {
sum2 += num1;
}
}
else {
cout << input << endl;
}
}
cout << "sum1 = " << sum1 << endl;
cout << "sum2 = " << sum2 << endl;
}
|
UNIX> g++ mystery.cpp UNIX> cat input.txt 3.6 14.5 -5 Brad Smiley 20. Jill Nancy 17.4 50 UNIX> ./a.out < input.txt 10 Mario |