| | |
C++ help for a newbie
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Mar 2005
Posts: 4
Reputation:
Solved Threads: 0
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
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
•
•
Join Date: Dec 2004
Posts: 489
Reputation:
Solved Threads: 5
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.
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.
•
•
Join Date: Mar 2005
Posts: 4
Reputation:
Solved Threads: 0
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.
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.
>so any suggestions on my program?
That's a good start for a simple pig latin program.
C++ Syntax (Toggle Plain Text)
#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" }
I'm here to prove you wrong.
![]() |
Similar Threads
- As a newbie, where i should start from in linux? (Getting Started and Choosing a Distro)
- Questions about building a system (was: newbie) (Troubleshooting Dead Machines)
- Best free C/C++ compiler for a newbie? (C++)
- help newbie alert needs help with login page (ASP.NET)
- newbie needs help, basic mfc stuff (C++)
- Hello, newbie here... (Geeks' Lounge)
- Book For Newbie (C++)
- Newbie - how do I start C++ programming? (C++)
- PHP newbie, project feasibility (PHP)
- How to network two Win98 machines (Networking Hardware Configuration)
Other Threads in the C++ Forum
- Previous Thread: Instantiating class objects??
- Next Thread: sentinel controlled while loop
| Thread Tools | Search this Thread |
api array based beginner binary c++ c/c++ calculator char char* class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news node numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






