Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In C++, string handling can be kinda challenging. But this topic pretty much sum

ID: 662366 • Letter: I

Question

In C++, string handling can be kinda challenging. But this topic pretty much summarizes all the things we have seen so far. The class string in C++ provides us many use features including:

a constructor that converts c-strings into string objects; as in:   char * cstr = "Hello"; string s( cstr );

a converting to produce a c-string from a string object; as in: char * cstr = s.c_str( );

a member that tells us the strings length; as in: int len = s.length( );

a member that produces a letter; as in: char c = s.at( 5 );

an operator that combines strings; as in: string u = s + t;

Using some of these string features, create a Scorer class which reads a pile of text and scores it according to the following criteria:
- each sentence should start with a CAPITAL letter. (+10 points each sentence)
- there should be two spaces following each period that ends each sentence. (+10 points each sentence)
- no sentence should be longer than 20 words. (-1 point for each word in a sentence with more than 20 word)
- no words longer than 10 letters (-1 point for each word in a sentence longer than 10 letters)
- the only words except for the start of a sentence that maybe capitalized should be "Santa Monica College" (-1 point for each capitalized word not starting a sentence)
- the only punctuation symbol allowed is an ending period (-1 point for each , - ; ! ? found)

A number of different program dialogues describe the program I am looking for.

Scorer();

void setString( string value );
void setCString( char * value );
void clear();
int getScore() const;

friend ostream& operator <<( ostream& outs, const Scorer & s );

Scorer s;
string str( "It's supercalifragilisticexpialidocious. Even though the sound of it is something quite atrocious if you say it loud enough, you'll always sound precocious, Supercalifragilisticexpialidocious." );

s.setCString( "Hello. My name is Howard Stahl. I teach at Santa Monica College in the CSIS department." );
cout << s << endl;
// should print: "Score = 57" // 60-3 = 57

s.clear();
s.setString( str );
cout << s << endl;
// should print: "Score = 14" // 20-6 = 14

s.clear();
s.setCString( "Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal. Now we are engaged in a great civil war, testing whether that nation, or any nation so conceived and so dedicated, can long endure. We are met on a great battlefield of that war. We have come to dedicate a portion of that field, as a final resting place for those who here gave their lives that that nation might live. It is altogether fitting and proper that we should do this." );
cout << s << endl;
// should print: "Score = 20" // 50-30 = 20

Class Diagram Sample Driver Code Scorer

Scorer();

void setString( string value );
void setCString( char * value );
void clear();
int getScore() const;

friend ostream& operator <<( ostream& outs, const Scorer & s );

string myString;

Scorer s;
string str( "It's supercalifragilisticexpialidocious. Even though the sound of it is something quite atrocious if you say it loud enough, you'll always sound precocious, Supercalifragilisticexpialidocious." );

s.setCString( "Hello. My name is Howard Stahl. I teach at Santa Monica College in the CSIS department." );
cout << s << endl;
// should print: "Score = 57" // 60-3 = 57

s.clear();
s.setString( str );
cout << s << endl;
// should print: "Score = 14" // 20-6 = 14

s.clear();
s.setCString( "Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal. Now we are engaged in a great civil war, testing whether that nation, or any nation so conceived and so dedicated, can long endure. We are met on a great battlefield of that war. We have come to dedicate a portion of that field, as a final resting place for those who here gave their lives that that nation might live. It is altogether fitting and proper that we should do this." );
cout << s << endl;
// should print: "Score = 20" // 50-30 = 20

Explanation / Answer

string str( "It's supercalifragilisticexpialidocious. Even though the sound of it is something quite atrocious if you say it loud enough, you'll always sound precocious, Supercalifragilisticexpialidocious." );

s.setCString( "Hello. My name is Howard Stahl. I teach at Santa Monica College in the CSIS department." );