VB icon

A simple strings sorting

Email
Submitted on: 1/3/2015 1:54:00 PM
By: Tahseen (from psc cd)  
Level: Beginner
User Rating: By 5 Users
Compatibility: C, C++ (general), Microsoft Visual C++, Borland C++
Views: 2332
 
     This code will make you understand simple by accepting 4 strings and sorting it through Bubble sort i trust this u help for C and C++ Beginner.
 

INCLUDE files:

Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
//**************************************
//INCLUDE files for :A simple strings sorting
//**************************************
#include <iostream.h>
#include <string.h>
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// Name: A simple strings sorting
// Description:This code will make you understand simple by accepting 4 strings and sorting it through Bubble sort i trust this u help for C and C++ Beginner.
// By: Tahseen (from psc cd)
//
// Inputs:Ask to enter 4 strings
//
// Returns:returns sorting strings
//
// Assumes:User should be aware of Arrays, boolean,for loops.
//
// Side Effects:Not much its only like beginiing of C and C++ Programer
//**************************************

#define ELEMENT 4
#define LENGTH 20
void getdata(char str[ELEMENT][LENGTH]);
void show(char str[ELEMENT][LENGTH]);
void sort(char str[ELEMENT][LENGTH]);
void main()
{
char str[ELEMENT][LENGTH];
cout<<"Find the sortin of string\n";
getdata(str);
sort(str);
show(str);
}
void getdata(char str[ELEMENT][LENGTH])
{
int loop;
for(loop=0;loop<ELEMENT;loop++)
{
	cin.getline(str[loop],LENGTH);
}
}
void sort(char str[ELEMENT][LENGTH])
{
char temp[LENGTH];
int loop;
bool flag;
do
{
 flag=false;
 for(loop=0;loop<ELEMENT;loop++)
 {
 	if(strcmp(str[loop],str[loop+1])>0)
 {
 	flag=false;
 strcpy(temp,str[loop]);
 strcpy(str[loop],str[loop+1]);
 strcpy(str[loop+1],temp);
 flag=false;
 }
 }
}while(flag!=false);
}
void show(char str[ELEMENT][LENGTH])
{
int loop;
cout<<endl;
for(loop=0;loop<ELEMENT;loop++)
{
	cout<<str[loop]<<endl;
}
}


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.