C++ help for a newbie

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Mar 2005
Posts: 4
Reputation: Jankos is an unknown quantity at this point 
Solved Threads: 0
Jankos Jankos is offline Offline
Newbie Poster

C++ help for a newbie

 
0
  #1
Mar 31st, 2005
Hi, i just started c++ programming in college this semester, and i have a project that i have no idea how to do. Im sure it will be extremely simple to all of you experts, but i just cant think of a way to do it. Maybe some of you could guide me in writing this program?

These are the instructions:

Write a program to translate input text into pig latin. The translation can be done character by character, without using string variables. The program skips non-alphabetic characters until it comes to an alphabetic character, which will be the first character of a word. If this character is a vowel, it reads and writes out the word with "ay" at the end. If the first character of the word is not a vowel, it writes out the word without its first character, and adds the original first character of the word plus "ay" at the end. Any blanks and punctuation marks should not be counted as part of a word, but should be written just as they are read. The program continues until an end of file(EOF) is read.

Use the principles of top-down design. Use the following functions as part of your program:
Skip_Non_Word() -- reads and writes blanks and punct. marks, and returns the first alphabetic character it finds.
Read_Word() -- reads and writes alphabetic characters, and returns the first non-alphabetic character it finds.
Is_Vowel() -- returns 1 if the character is a vowel, and 0 otherwise.

make sure your code handles end-of-file gracefully(without getting stuck in a loop)

DUE DATE: April 5

p.s. Thank you for your time
p.p.s. I am using visual c++ 6, and it must be a console program
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 489
Reputation: Acidburn is an unknown quantity at this point 
Solved Threads: 5
Acidburn Acidburn is offline Offline
Posting Pro in Training

Re: C++ help for a newbie

 
0
  #2
Mar 31st, 2005
rather than giving the code for homework, whilst I still appricate the fact that you cannot / think you cannot do this. Even though you can.

Could you write some pesudeo code and bang that up here, along with an first attempt at the code? I'm sure we'll all iron out the code bugs, but first we need something to see that you are trying. Plus its the only way to learn is to sit down infront of a compiler and make bugs! Then spend the rest of the time learning from the bugs.
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 4
Reputation: Jankos is an unknown quantity at this point 
Solved Threads: 0
Jankos Jankos is offline Offline
Newbie Poster

Re: C++ help for a newbie

 
0
  #3
Mar 31st, 2005
well it needs to be made in a combination of C and c++ really, and i dont know that much about C.

void main()
{
cout << "Enter a sentence to be converted to pig latin";
char c=getchar(c) //no idea how to use getchar, getch, and getche but something like this?
if(isalpha(c))
read_word(); //i guess here it would call Is_Vowel() and return 1 or o and if its 1, it reads in the rest of the string? I dunno how to get a sentence in...
}

bout all i have for now, im not very good at the C stuff, but im ok in c++.
im not here to have someone do my homework for me if thats what u think. I want to learn how to do this because i want to do it for the rest of my life, i just need some guidance and direction.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,566
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 705
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: C++ help for a newbie

 
0
  #4
Mar 31st, 2005
>well it needs to be made in a combination of C and c++ really
Why? Unless you're familiar with C, the only possible result of trying to mix the two is a lot of compilation and run-time errors.

>void main()
This is neither C nor C++. main always returns int.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 4
Reputation: Jankos is an unknown quantity at this point 
Solved Threads: 0
Jankos Jankos is offline Offline
Newbie Poster

Re: C++ help for a newbie

 
0
  #5
Mar 31st, 2005
i thought it did anyway

and my professor told us to use void main() instead of int main()
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,566
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 705
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: C++ help for a newbie

 
0
  #6
Mar 31st, 2005
>and my professor told us to use void main() instead of int main()
That explains so much it's not even funny. Your professor doesn't know nearly as much as he probably thinks he does. In my opinion, one should learn the language before trying to teach it.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 4
Reputation: Jankos is an unknown quantity at this point 
Solved Threads: 0
Jankos Jankos is offline Offline
Newbie Poster

Re: C++ help for a newbie

 
0
  #7
Mar 31st, 2005
yeah probably, so any suggestions on my program?
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,566
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 705
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: C++ help for a newbie

 
0
  #8
Mar 31st, 2005
>so any suggestions on my program?
  1. #include <cstdlib>
  2. #include <iostream>
  3.  
  4. void pig_latin ( const char *line );
  5.  
  6. int main()
  7. {
  8. char line[1024];
  9.  
  10. cout<<"Enter a sentence: ";
  11. if ( !cin.getline ( line, sizeof line ) ) {
  12. cerr<<"Invalid input"<<endl;
  13. return EXIT_FAILURE;
  14. }
  15.  
  16. pig_latin ( line );
  17.  
  18. return EXIT_SUCCESS;
  19. }
  20.  
  21. void pig_latin ( const char *line )
  22. {
  23. // Walk across the string until you hit '\0'
  24. // Save all characters up to a vowel
  25. // Print all characters up to a space
  26. // Print the saved characters
  27. // Print "ay"
  28. }
That's a good start for a simple pig latin program.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC