I SUCK at computer programming, I thought I would be good at it, but I suck and Im stuck struggling in this class. If anyone can help me with my homework it would be GREATLY appreciated.
I need to write a program that:
makes leading and trailing spaces are removed (" Hello " becomes "Hello"),
makes multiple spaces between words are replaced with a single space ("Hello World" becomes "Hello World"),
The case of the characters is changed so that all words start with upper case letter and continue with lower case letters ("hello WORLD" becomes "Hello World"), except for:
words "and", "a", "the", and "of" which should be all in lower case unless the word is the first word of the text ("the Lord OF The rings" converts to "The Lord of the Rings",
words in {} braces should retain the case and the braces are removed ("{PBO} {InterOperability} Laboratory" translates to "PBO InterOperability Laboratory"). Braces will NOT be nested, i.e., "{{ABC}def}" - it would make any sense given their function.
Code:
#include <iostream>
using namespace std;
void titleFormat(char line[]) {
// Formats the line according to the "title" format
// your code goes here
int i=0, j=0;
char temp[128] ;
while(line[i]!= '\0') {
if (line[i]!= ' ')
temp[j++] = line[i];
i++;
temp[i]= '\0'
strcmp (line, temp)
}
}
void checkLine(char line[]) {
// a helper finction to avoid repetive code, calls titleFormat function and
// prints the "before" and "after" content of line with >< markers to show
// leading and trailing spaces
cout << "Before: >" << line << '<' << endl;
titleFormat(line);
cout << "After : >" << line << '<' << endl << endl;
}
int main () {
char testLine1[] = " Hello ";
checkLine(testLine1);
char testLine2[] = "Hello World";
checkLine(testLine2);
char testLine3[] = "hello WORLD";
checkLine(testLine3);
char testLine4[] = "the Lord OF The rings";
checkLine(testLine4);
char testLine5[] = "{PBO} {InterOperability} Laboratory";
checkLine(testLine5);
const int LINE_LENGTH = 256;
char line[LINE_LENGTH];
cout << "Enter your line of text : ";
cin.getline(line, LINE_LENGTH);
checkLine(line);
return 0;