C++ HELP PLEASE!

  • (4 Pages)
  • +
  • 1
  • 2
  • 3
  • Last »

53 Replies - 2379 Views - Last Post: 05 March 2010 - 06:10 AM Rate Topic: -----

#1 Guest_Sabrina*


Reputation:

C++ HELP PLEASE!

Posted 03 March 2010 - 09:54 PM

Hi! I have to complete this C++ programming assignment and I am having a lot of trouble. Is there anyone out there who can provide me with an answer? Here is the assignment...

Part A: (can be done in lab, and graded before leaving)
if you only do "capitalize all" you get 25 points.

cd to your "asst2" directory.

Create a filter program* called asst2.cpp which capitalizes and
prints all characters which it reads in. Use cin.get() to read
(input) from the keyboard character by character, and then use the

int toupper(int)

function to change the alpha characters to uppercase .

use the cout.put(char) function to output the char.

Wrap these in a loop structure which processes all characters
typed.

To get you started, here is a skeleton program you can copy and
modify. Note: this program only prints out what it takes in, with
no modification:

/*-----------------------------------------------------------------
* replace this text with program title and programmer name and date.
*	
-----------------------------------------------------------------*/
#include <stdio.h>
#include <iostream>
using namespace std;

int main (int argc, char *argv[], char **env)
{
	char c, lastc = ' ' ;
	c = cin.get() ;
	do {
		/* part B IF statement and case conversion goes here */
		cout.put(c) ;
	//	lastc = c ; // THIS IS IMPORTANT FOR PART b: first char only.
		c = cin.get() ;
	} while ( !cin.eof()) ;
}



===========================

Part B worth 50 points: how would you re-write the code to
capitalize ONLY THE FIRST LETTER of each word?

(This is a sneaky way of asking you what is the identifying
characteristic of the beginning of a word, and how could the
program discover it? Programming often makes us re-examine
what we know and how we know it.)

Hint: C has a function called isspace(int)

This function will return true if the argument passed to it
is a space, tab, newline, formfeed, etc. So I ask you again:
what is the identifying characteristic of the first character
in a word?

This post has been edited by no2pencil: 03 March 2010 - 09:56 PM
Reason for edit:: Added code tags


Is This A Good Question/Topic? 0

Replies To: C++ HELP PLEASE!

#2 no2pencil  Icon User is online

  • Toubabo Koomi
  • member icon

Reputation: 5178
  • View blog
  • Posts: 26,870
  • Joined: 10-May 07

Re: C++ HELP PLEASE!

Posted 03 March 2010 - 09:57 PM

View PostSabrina, on 03 March 2010 - 10:54 PM, said:

int toupper(int)

How are you going to upper case an integer?
Was This Post Helpful? 0
  • +
  • -

#3 gsekhon  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 24
  • Joined: 18-February 10

Re: C++ HELP PLEASE!

Posted 03 March 2010 - 10:04 PM

View Postno2pencil, on 03 March 2010 - 08:57 PM, said:

View PostSabrina, on 03 March 2010 - 10:54 PM, said:

int toupper(int)

How are you going to upper case an integer?


That's actually the correct signature for the toupper function in C++. Upper and lower case letters are separated by decimal 32, with lower case having higher number than upper case in ASCII chart.
Was This Post Helpful? 0
  • +
  • -

#4 wild494  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 86
  • Joined: 20-May 09

Re: C++ HELP PLEASE!

Posted 03 March 2010 - 10:05 PM

Did you want help with the assignment or did you want someone to give you the answer?
Was This Post Helpful? 1
  • +
  • -

#5 no2pencil  Icon User is online

  • Toubabo Koomi
  • member icon

Reputation: 5178
  • View blog
  • Posts: 26,870
  • Joined: 10-May 07

Re: C++ HELP PLEASE!

Posted 03 March 2010 - 10:13 PM

View Postgsekhon, on 03 March 2010 - 11:04 PM, said:

View Postno2pencil, on 03 March 2010 - 08:57 PM, said:

View PostSabrina, on 03 March 2010 - 10:54 PM, said:

int toupper(int)

How are you going to upper case an integer?


That's actually the correct signature for the toupper function in C++. Upper and lower case letters are separated by decimal 32, with lower case having higher number than upper case in ASCII chart.

#include <stdio.h>

int main(void) {
  int ch1,ch2=112;
  ch1=toupper(ch2);
  printf("Was : %c\nIs %c\n",ch2,ch1);
  return 0;
}



Quote

$./int
Was : p
Is P


That's pretty cool.
Was This Post Helpful? 0
  • +
  • -

#6 Guest_Guest*


Reputation:

Re: C++ HELP PLEASE!

Posted 03 March 2010 - 10:18 PM

I just tried that code but it said that the toupper wasn't declared. What does that mean?
Was This Post Helpful? 0

#7 gsekhon  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 24
  • Joined: 18-February 10

Re: C++ HELP PLEASE!

Posted 03 March 2010 - 10:20 PM

View PostGuest, on 03 March 2010 - 09:18 PM, said:

I just tried that code but it said that the toupper wasn't declared. What does that mean?


Means you're missing header files. To use toupper function you need to include(from MSDN library) :
<stdlib.h> and <ctype.h>

Which he did indirectly by including <stdio.h>
Was This Post Helpful? 0
  • +
  • -

#8 Guest_Guest*


Reputation:

Re: C++ HELP PLEASE!

Posted 03 March 2010 - 10:24 PM

Do I need to add something to make it work?
Was This Post Helpful? 0

#9 gsekhon  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 24
  • Joined: 18-February 10

Re: C++ HELP PLEASE!

Posted 03 March 2010 - 10:34 PM

View PostGuest, on 03 March 2010 - 09:24 PM, said:

Do I need to add something to make it work?


If you copied his code straight then it should work. If you copied only the main, then add a "#include <stdio.h>"
Was This Post Helpful? 0
  • +
  • -

#10 Guest_Guest*


Reputation:

Re: C++ HELP PLEASE!

Posted 04 March 2010 - 12:07 AM

It is still giving me the same error message. Thank you for the help everyone. I don't know why this code isn't working...
Was This Post Helpful? 0

#11 no2pencil  Icon User is online

  • Toubabo Koomi
  • member icon

Reputation: 5178
  • View blog
  • Posts: 26,870
  • Joined: 10-May 07

Re: C++ HELP PLEASE!

Posted 04 March 2010 - 12:09 AM

#include <stdio.h>
#include <ctype.h>

int main(void) {
  int ch1,ch2=112;
  ch1=toupper(ch2);
  printf("Was : %c\nIs %c\n",ch2,ch1);
  return 0;
}

Was This Post Helpful? 0
  • +
  • -

#12 Guest_Guest*


Reputation:

Re: C++ HELP PLEASE!

Posted 04 March 2010 - 12:15 AM

THANK YOU!!! THIS WORKED!!!

I have one more question if anyone can help. Here is the task...

Part A: (can be done in lab, and graded before leaving)
if you only do "capitalize all" you get 25 points.

cd to your "asst2" directory.

Create a filter program* called asst2.cpp which capitalizes and
prints all characters which it reads in. Use cin.get() to read
(input) from the keyboard character by character, and then use the

int toupper(int)

function to change the alpha characters to uppercase .

use the cout.put(char) function to output the char.

Wrap these in a loop structure which processes all characters
typed.

To get you started, here is a skeleton program you can copy and
modify. Note: this program only prints out what it takes in, with
no modification:

/*-----------------------------------------------------------------
* replace this text with program title and programmer name and date.
*	
-----------------------------------------------------------------*/
#include <stdio.h>
#include <iostream>
using namespace std;

int main (int argc, char *argv[], char **env)
{
	char c, lastc = ' ' ;
	c = cin.get() ;
	do {
		/* part B IF statement and case conversion goes here */
		cout.put(c) ;
	//	lastc = c ; // THIS IS IMPORTANT FOR PART b: first char only.
		c = cin.get() ;
	} while ( !cin.eof()) ;
}

This post has been edited by JackOfAllTrades: 04 March 2010 - 04:29 AM
Reason for edit:: Added code tags.

Was This Post Helpful? 0

#13 Guest_Guest*


Reputation:

Re: C++ HELP PLEASE!

Posted 04 March 2010 - 12:16 AM

How can I manipulate this skeleton to make it work correctly???
Was This Post Helpful? 0

#14 no2pencil  Icon User is online

  • Toubabo Koomi
  • member icon

Reputation: 5178
  • View blog
  • Posts: 26,870
  • Joined: 10-May 07

Re: C++ HELP PLEASE!

Posted 04 March 2010 - 12:16 AM

That's not a question, that's your assignment. Feel free to ask a question, but we are not going to do that for you.
Was This Post Helpful? 0
  • +
  • -

#15 Guest_Guest*


Reputation:

Re: C++ HELP PLEASE!

Posted 04 March 2010 - 12:22 AM

I did ask a question. I understand how the skeleton works because I've been reading the textbook but everything I have tried has not worked. I thought it would be easier to show everyone what I am looking at. I wasn't looking for anything else. I believe I can speak freely here....
Was This Post Helpful? 0

  • (4 Pages)
  • +
  • 1
  • 2
  • 3
  • Last »