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

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.

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.

>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 thought it did anyway

and my professor told us to use void main() instead of int main()

>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.

>so any suggestions on my program?

#include <cstdlib>
#include <iostream>

void pig_latin ( const char *line );

int main()
{
  char line[1024];

  cout<<"Enter a sentence: ";
  if ( !cin.getline ( line, sizeof line ) ) {
    cerr<<"Invalid input"<<endl;
    return EXIT_FAILURE;
  }

  pig_latin ( line );

  return EXIT_SUCCESS;
}

void pig_latin ( const char *line )
{
  // Walk across the string until you hit '\0'
    // Save all characters up to a vowel
    // Print all characters up to a space
    // Print the saved characters
    // Print "ay"
}

That's a good start for a simple pig latin program.

This article has been dead for over six months. Start a new discussion instead.