Hi
I'm very new to programming and have purchased the book by Andrew Koenig and Barbara Moo. I am a tad frustrated at the moment because I cannot fiigure out the following from Q3.4 in the exercises:
-> How do I calculate the size of the strings in a vector that I've created?
-> How do I then keep the maximum and minumum of the strings the user
enters to ouput the respective longest and shortest strings?
Here is my code thus far :
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <ios>
#include <string>
#include <vector>
using std::cin; using std::sort;
using std::cout; using std::endl;
using std::string; using std::streamsize ;
using std::vector; using std::setprecisi on;
int main()
{
// ask for and read the user's name
cout << "Please enter your first name: ";
string name;
cin >> name;
cout << "Hello, " << name << "!" << endl;
// ask for and read family member's names
cout << "Please enter all your family members names, "
"followed by end-of-file: ";
vector<string> family;
string x;
// invariant:famil y contains all family names read so far
while (cin >> x)
family.push_bac k(x);
// check that the user entered some names
typedef vector<string>: :size_type vec_sz;
vec_sz size = family.size();
if (size == 0) {
cout << endl << "You must enter two or more family names. "
"Please try again." << endl;
system("PAUSE") ;
return 1;
}
// sort the names
sort(family.beg in(), family.end());
// run through the vector elements using r rows of input
int max = family[0].size();
int r = 0;
for (int r = 0; r != family.size(); ++r) {
while (cin >> x)
string::size_ty pe name_size = family[x].size();
??Aggghhh! Please help.}
system("PAUSE") ;
return 0;
}
If anyone can help I'd really really appreciate it.
Thanks
M
I'm very new to programming and have purchased the book by Andrew Koenig and Barbara Moo. I am a tad frustrated at the moment because I cannot fiigure out the following from Q3.4 in the exercises:
-> How do I calculate the size of the strings in a vector that I've created?
-> How do I then keep the maximum and minumum of the strings the user
enters to ouput the respective longest and shortest strings?
Here is my code thus far :
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <ios>
#include <string>
#include <vector>
using std::cin; using std::sort;
using std::cout; using std::endl;
using std::string; using std::streamsize ;
using std::vector; using std::setprecisi on;
int main()
{
// ask for and read the user's name
cout << "Please enter your first name: ";
string name;
cin >> name;
cout << "Hello, " << name << "!" << endl;
// ask for and read family member's names
cout << "Please enter all your family members names, "
"followed by end-of-file: ";
vector<string> family;
string x;
// invariant:famil y contains all family names read so far
while (cin >> x)
family.push_bac k(x);
// check that the user entered some names
typedef vector<string>: :size_type vec_sz;
vec_sz size = family.size();
if (size == 0) {
cout << endl << "You must enter two or more family names. "
"Please try again." << endl;
system("PAUSE") ;
return 1;
}
// sort the names
sort(family.beg in(), family.end());
// run through the vector elements using r rows of input
int max = family[0].size();
int r = 0;
for (int r = 0; r != family.size(); ++r) {
while (cin >> x)
string::size_ty pe name_size = family[x].size();
??Aggghhh! Please help.}
system("PAUSE") ;
return 0;
}
If anyone can help I'd really really appreciate it.
Thanks
M
Comment