HEY YOU!!!, Our records indicate that you have never posted to our site before! Why not make your first post today by saying hello to our community in our new people forums. To access all the good good stuff you need to post, post, and post more.


Support Webrats Forum with your Subscription. Only $5.95 per month!
Adult lounge Access • Private Messaging • GAMES •
Please click here for more details • Please click here to subscribe
Go Back   WR > Community > Computers and Programming
User Name
Password
Register Help Desk Music Uploads Live Cams Arcade Upgrade Account Mark Forums Read
Reply
 
Thread Tools
Old 04-03-2005, 01:46 PM   #1
jcoop
whore
 
 
Join Date: Mar 2005
Location: New hampshire
Posts: 134/0.10
Threads: 2
MALE
Homework help (C++)

click on one of our sponsors! OR REMOVE ADS
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;
Submit to Clesto Submit to Digg Submit to Reddit Submit to Furl Submit to Del.icio.us Submit to Spurl | quote |
Sponsored Links
REMOVE ADS
Reply

WR > Community > Computers and Programming
Reload this Page Homework help (C++)
Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:

Powered by Waldo 12345678910 1213 14 15 Copyright © 2000-2005 Jelsoft Enterprises Limited.
Page generated in 0.36016607 seconds (85.26% PHP - 14.74% MySQL) with 13 queries
206.212.255.30 Message Boards and Forums Directory