[Snark] C++ myfunc1

Aidan submissions at badcode.rocks
Fri Oct 26 01:39:12 UTC 2018


I have graded a high school computer science class, and I tried my best to 
take inspiration from the work of those students for my submission. My 
submission does not consider capitalized letters.

== License ==

This is my own work, and is licensed under CC0.

== PigLatin.h ==

#include <string>
#include <map>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
class PigLatin {
public:
void pig(string string);
void myfunc1(string string);
private:
int test();
};

== PigLatin.cpp ==

#include "PigLatin.h"

bool a = false;

int main(int argv, char **argc)
{
	// check for 1 argument
        if( argv == 1 ){
          return 0;
        };
        a = true;
        PigLatin piglatin;
        piglatin.myfunc1(argc[1]);
        cout << "\n"; }

void PigLatin::pig(string s_word)
{
	int a = 0;
	if( s_word[0] == 'a' || s_word[0] == 'e' || s_word[0] == 'i' || s_word[0] == 'o' || s_word[0] =='u' ||
	(s_word.size() > 1 && ((s_word[0] == 'x' &&
	s_word[1] == 'r') || (s_word[0] == 'y' && s_word[1] == 't'))))
	{
	    string mystring;
	    mystring = s_word + "ay";
	    cout << mystring;
	    return;
	}
	else
	{
      
	string str;
        for (int i = 0; a < s_word.size(); a++) {
        	if (s_word[a] == 'a' || s_word[a] == 'e' || s_word[a] == 'i' || s_word[a] == 'o' || s_word[a] == 'u' || (s_word[a] == 'y' && 0 < a)) {
        		a = s_word.size();
        	}
        	else
        	if(s_word.size() > 1+a && s_word[a]=='q' && s_word[a+1] == 'u')
        	{
        		if (s_word[a] == 'q' && s_word[a+1] == 'u')
        		{
        			str = str + "qu";
        			a = s_word.length();
        		};
        	}
        	else
        		str = str + s_word[a];
        	;
        };
	string mystring;
	mystring = s_word.substr (str.length());
	mystring = mystring  +str + "ay";
	cout << mystring;

	}

	return ;
}

int PigLatin::test()
{
return 0;
}

void PigLatin::myfunc1(string s) {
	string usethis;
	for (int b = 0; b < s.size(); b++) {
		if(s[b] == ' ') {
			if (b > 0) {
	if (a == true) {
		pig (usethis);
		a = false;
				}
				else

                                {
                                	cout << " ";
                                	pig(usethis);
                                };
			}
			myfunc1(s.substr(b + 1));
			return;
		} else
			// append s[b] to usethis
			usethis += s[b];
		;
	};


	if (usethis.length( ) > 0) { if (a!= 1) {
			cout << " ";
			pig(usethis);
		}
		else{
			pig(usethis);
			a = false;
		};
	}; }


More information about the Snark mailing list