Post your C/C++ Programs Here

Status
Not open for further replies.

mayoorite

Night Fury
Re: Pattern by a beginner

I
mean making it more simpler(code) & adding more different patterns/shape,symbols.
 

Liverpool_fan

Sami Hyypiä, LFC legend
You'll be even more surprised to find such people here in TDF as well, and they are like "aise hi chalta hai, et al". And they are IT "professionals" apparently.
 

Garbage

God of Mistakes...
I haven't seen any biggies using TC++ in their trainings. Heck, I haven't seen any biggies training in C / C++. :p
 

somulesnar

Journeyman
guys need a little help.. i recently wrote a program to implement the piglatin concept but unfortunately the program doesnt give output... here is the code

Code:
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
void initialize(char[],char[]);
void readinput(char english[]);
int countwords(char english[]);
void convert(int words, char english[], char piglatin[]);
void writeoutput(char piglatin[]);
int main()
{
	char english[80], piglatin[80];
	int words;
	printf("Welcome to the Piglatin Generator\n\n");
	printf("Type \'END\'when finished\n\n");
	do {
		/*process a new line of text*/
		initialize(english, piglatin);
			printf("now before read input");
		readinput(english);
		printf("now after read input");
		/*count the no of words in the line*/
 		  words=countwords(english);
 		/*convert english to piglatin*/
 		printf("now before writeoutput");
		 writeoutput(piglatin);
 		break;
		}
	while(words>=0);
	printf("\naveh aa icena ayda (Have a nice day)\n");
}
/*intialize the character arrays with blank spaces*/
void initialize(char english[],char piglatin[])
{
	int count;
	for(count=0;count<80;++count)
	english[count]=piglatin[count]=' ';
}
/*read one line of English text*/
void readinput(char english[])
{
	int count=0;
	char c;
	while(count < 15)
	{
		c=getchar();
		english[count]=c;
		++count;
	}
	printf("now in read input");
	return;
}
/*scan the english text and determine the number of words*/
int countwords(char english[])
{
	int count, words=1;
	for(count=count<79;++count;)
	if(english[count]==' '&& english[count+1] !=' ')
	++words;
	return(words);
}
/*convert each word into piglatin*/
void convert(int words,char english[],char piglatin[])
{
	int n, count;
	int m1=0;
	int m2;
	/*convert each word*/
	for(n=1;n<=words;++n)
	{
		/*locate the end of the current word*/
		count=m1;
		while(english[count]!=' ')
		m2=count++;
		/*transpoes the first letter and add a*/
		for(count=m1;count<m2;++count)
		piglatin[count+(n-1)]=english[count+1];
		piglatin[m2+(n-1)]=english[m1];
		piglatin[m2+n]='a';
		/*reset the initial maarker*/
		m1=m2+2;
		
	}
	return;
}
/*display the line of text in piglatin*/
void writeoutput(char piglatin[])
{
	int count=0;
	for(count=0;count<80;++count)
	putchar(piglatin[count]);
	printf("\n");
	return;
}


i am using turbo c++ compiler right now...... plz need suggestion urgently( program code is in c language so need answers in the same)..
cheers...
 

Neuron

Electronic.
for making FLAT ATFLAY

1.read the word.
2.determine the number of letters in the word.
3.find the start position of the consonant cluster.
4.copy the words before the cluster to a temporary string.
5.print the output as right side of the cluster start position+temporary string+ay.
 

somulesnar

Journeyman
@neuron

Dont really get u buddy sorry but i am a novice......
so plz try helping me by writing code itself..... or pointing my mistakes in my code.....

hey guys here's another simple bubble sort program..........

here the values are given by default u can also code it to enter the values manually.......

#include<stdio.h>
#include<conio.h>
void main()
{
int arr[5]={25,17,31,13,2};
int i,j,temp;
clrscr();
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
if(arr[j]>arr[j+1])
{
temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
}
}
}
printf("The array after sorting is: ");
for(i=0;i<=4;i++)
printf("%d\n",arr);
getch();
}

cheers....
 

Neuron

Electronic.
The major problem is with the convert() function.I don't understand what you are trying to implement .Especially these 2 statements
Code:
piglatin[count+(n-1)]=english[count+1];
piglatin[m2+(n-1)]=english[m1]

Secondly, in the code you posted the convert() function isn't called from the main() function.
 

vickybat

I am the night...I am...
@ somulesnar

I have written a very simple english(word) to piglatin converter code in c++. It uses the string concept which i'm still learning.

It simply rotates the input string and concatenates "ay".

For example- "batman"

piglatin- "atmanbay"


Code:
[B]# include <iostream>
#include <string>

using namespace std;
 
string str;
 string pstr;
string piglatin( string pstr);

int main()

{
    
    cout<<"enter the string:"<<endl;
    cin>>str;
    cout << " The piglatin form of the input string is:"<<piglatin(str)<<endl;
     cin.ignore();
     cin.get();
    
    return 0;
    
}

string piglatin(string pstr)

{
      string::size_type len=pstr.length();
	  string rstr;
      rstr=pstr.substr(1,len-1)+pstr[0];//[B] [COLOR="Blue"]rotates the string[/COLOR][/B]
      
      pstr = rstr + "ay";
	
       return pstr;
      
      
       
       cin.get();
    cin.ignore();
       
       }[/B]


Guys give your expert opinions on it.:smile:
 

Liverpool_fan

Sami Hyypiä, LFC legend
Why the cin.get() and cin.ignore() in piglatin()? These statements will have no effect, since control is returned before them.
And let me guess their presence in main() is to trap keyboard to see output? You need a better IDE in that case.
And why are you using global variables in the program? They are certainly not needed.
 

Neuron

Electronic.
@vickybat:There is a small problem with the piglatin concept you used.It's not like the first letter is brought to the end and an 'ay' is added,but its a consonant cluster that is rotated to the end. ie,scram should produce 'amscray' and not 'cramsay' since the first consonant cluster is 'scr'.
 

vickybat

I am the night...I am...
@vickybat:There is a small problem with the piglatin concept you used.It's not like the first letter is brought to the end and an 'ay' is added,but its a consonant cluster that is rotated to the end. ie,scram should produce 'amscray' and not 'cramsay' since the first consonant cluster is 'scr'.

Yeah but wikipedia gave me this:

Pig Latin is a language game of alterations played in English. To form the Pig Latin form of an English word the first consonant (or consonant cluster) is moved to the end of the word and an ay is affixed (for example, pig yields ig-pay and computer yields omputer-cay). The object is to conceal the meaning of the words from others not familiar with the rules. The reference to Latin is a deliberate misnomer, as it is simply a form of jargon, used only for its English connotations as a "strange and foreign-sounding language."

Its doing the same thing that i did. Can you throw some more light on this fact mate?:smile:
 

vickybat

I am the night...I am...
Why the cin.get() and cin.ignore() in piglatin()? These statements will have no effect, since control is returned before them.
And let me guess their presence in main() is to trap keyboard to see output? You need a better IDE in that case.
And why are you using global variables in the program? They are certainly not needed.

You got that right friend. I'm using dev-c++ and its forcing me to add cin.ignore and cin.get to trap keyboard to see output like you said.

Yes i had added them unnecessarily to the piglatin function.

About IDE, mate i had a lot of trouble with code::blocks today. It refused to compile and threw an error stating that iostream is not part of the directory.

Now i searched here and there in the web and found out a few solutions which stated to give the minigw path manually.

But everything went in vain and it just didn't compile anything and i had to revert back to dev c++.

Suggest me what to do mate??

Search the same wikipedia page for the word 'scram'.

Yeah saw it. Scram is amscray. Why is that?

Oh- you mean i have to add a vowel check method to turn the consonant cluster??
 

Neuron

Electronic.
pig is igpay because the 2nd letter itself is a vowel(i).So the left of 'i' is rotated.Same with computer o is a vowel.So c alone is there to be rotated.
Similarly in scram ,the left of the firstly found vowel is rotated,ie,the left of a,'scr'.If it was
cjkdkomputer then the piglatin will be omputercjkdkay.
 

vickybat

I am the night...I am...
pig is igpay because the 2nd letter itself is a vowel(i).So the left of 'i' is rotated.Same with computer o is a vowel.So c alone is there to be rotated.
Similarly in scram ,the left of the firstly found vowel is rotated,ie,the left of a,'scr'.If it was
cjkdkomputer then the piglatin will be omputercjkdkay.

Oh got it mate. Thanks for that.:smile: I will modify the code accordingly.

I guess a switch case to check vowels will do isn't it?
And to do that we have to check each and every character of the string.
Loops will also be needed.
 
Status
Not open for further replies.
Top Bottom