Any C++ programmers here? Help Needed...

Illuminatos

#OVOXO
Joined
Jun 19, 2012
Messages
46,096
Reputation
4,063
Daps
194,430
Reppin
NULL
I ain't want to do this but I'm about to go crazy over here. :whoa::bryan:

Basically I have to take the Gettysburg Address and convert it into pig latin. :snoop:

Gettyburg Address
Abraham Lincoln

Four score and seven years ago our fathers brought forth on this
continent a new nation, conceived in liberty, and dedicated to the
proposition that all men are created equal. Now we are engaged in a
great civil war, testing whether that nation, or any nation so conceived
and so dedicated, can long endure. We are met on a great battlefield of
that war. We have come to dedicate a portion of that field, as a final
resting place for those who here gave their lives that that nation might
live. It is altogether fitting and proper that we should do this. But,
in a larger sense, we cannot dedicate--we cannot consecrate--we cannot
hallow this ground. The brave men, living and dead, who struggled here,
have consecrated it, far above our poor power to add or detract. The
world will little note, nor long remember, what we say here but it can
never forget what they did here. It is for us the living, rather to be
dedicated here to the unfinished work which they who fought here have
thus far so nobly advanced. It is rather for us to be here dedicated to
the great task remaining before us,--that from these honored dead we
take increased devotion to that cause for which they gave the last full
measure of devotion--that we here highly resolve that these dead shall
not have died in vain--that this nation, under God, shall have a new
birth of freedom--that government of the people, by the people, for the
people, shall not perish from the earth.

I have to take the first letter of each word, put it at the end of the word and add an "ay" at the end. So for example "Four score and seven" would be "Ourfay coresay ndaay evensay." After that I have to count the number of words, letters and characters in the file.

The 2nd part is easy but the actual converting the text into pig latin has me losing my mind. I've been going at it for the last three days and I just can't figure it out.

The professor says to process each letter one at a time but I don't know how to store the letter and put it into the end of the word. :jbhmm:

This is what my main is looking like

LRktka1.png



Basically this puts an ay at the end of every word except for words that start a new line. :snoop:

I just need help with the converting to pig latin part, I can do the word/letter counting. I'm not asking you to do my assignment but any hints/advice would be helpful.:martin:

EDIT: Btw this is what I get when I run the program in the OP.

WO3i1TG.png
 
Last edited:

Matt504

YSL as a gang must end
Joined
Sep 7, 2013
Messages
45,443
Reputation
15,239
Daps
275,807
why aren't you doing this instead?
Code:
outfile.put('ay ');

of course this isn't the solution, just curious.
 

FSP

Banned
Joined
Jun 19, 2015
Messages
14,284
Reputation
1,108
Daps
42,300
Don' you have to put the first syllable last and then add ay?
Good thing I don't know C++ :whew:
 

Dr. Acula

Posts on Dapcity.com
Supporter
Joined
Jul 26, 2012
Messages
26,960
Reputation
9,402
Daps
144,275
in actually going to try and help breh. Let me get to my desktop.

Is this all of the code? Is there any function definition,classes, structs outside of the main function?
 

Dr. Acula

Posts on Dapcity.com
Supporter
Joined
Jul 26, 2012
Messages
26,960
Reputation
9,402
Daps
144,275
Alright I'm at my desktop. Let me take a look and get back to you.
 

FSP

Banned
Joined
Jun 19, 2015
Messages
14,284
Reputation
1,108
Daps
42,300
Ever think about indexing all of your chars of your words inside an array and then doing the logic on each word?
 
  • Dap
Reactions: Sir

Illuminatos

#OVOXO
Joined
Jun 19, 2012
Messages
46,096
Reputation
4,063
Daps
194,430
Reppin
NULL
in actually going to try and help breh. Let me get to my desktop.

Is this all of the code? Is there any function definition,classes, structs outside of the main function?

This is everything.

Code:
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <cctype>
#include <string>

using namespace std;

ofstream outfile ("GettysburgAddressPigLatin.txt");
ifstream infile ("GettysburgAddress.txt");


int main()
{

    int c, words;

    if (!infile.is_open()) {
        cout << endl << "ERROR: Unable to open input file" << endl;
        exit(1);
    }

    if (!outfile.is_open()) {
        cout << endl << "ERROR: Unable to open output file" << endl;
        exit(1);
    }

    while (!infile.eof()) {
        c = infile.get();

            if (isblank(c))
                outfile.put('a'),
                outfile.put('y'),
                outfile.put(' ');

            else if (ispunct(c))
                    outfile.put(' ');

            else if (c == '\n')
                    ;

                outfile.put(c);


    }

    outfile.close();
    infile.close();
    return EXIT_SUCCESS;

}

/*void characterAmount
{

        while (!infile.eof()) {
          c = infile.get();
          ++words;
          outfile.put(c);
    }

              outfile << "There are: " << words << " in this file." << endl;

}*/

Note the last part is just the character count. I just threw that together real quick and was gonna edit it after I finished pig latin converting so I put it in a comment. :snoop:

I also have to put everything into its own separate functions but I was also gonna do that after I got all the pig latin converting done and was editing my style. :sadcam:
 

Illuminatos

#OVOXO
Joined
Jun 19, 2012
Messages
46,096
Reputation
4,063
Daps
194,430
Reppin
NULL
Ever think about indexing all of your chars of your words inside an array and then doing the logic on each word?

I was gonna do an array but I'm still not comfortable with them. :snoop:

I literally started this class 4 weeks ago. Take C++ in the summer brehs. :sadcam:
 

SheWantTheD

Veteran
Joined
Sep 10, 2015
Messages
41,712
Reputation
2,587
Daps
104,198
when's it due breh? :mjlol:

It's gon be hell when you start getting very hard assignments..

I had to do an assignment building an entire goddamn poker game in an intro comp sci course WTF?!

And it doesn't get any easier here on out.
 
Top