Вы находитесь на странице: 1из 12

//algorithm project

#include<iostream.h>
#include<string.h>
#include<iomanip.h>
struct employ_status
{
char name[50]; char id[10]; char birth_p[40]; char birth_d[20];
double salary; } em[100]; struct student_name{
char name[50]; char id[10]; };
int n,cheack=0,output;
char Binary_search(); char Linear_search();char Selection_sort(); char
Insertion_sort();
char Bubble_sort(); char Record_data(); char Group_members();
int main(){
cout<<"\t\tWelcome To Our Mini Project\n\n";
cout<<"\nPlease frist record data befor you do something\n";
w:cout<<"\n\t*********======MAIN======*********\n";
cout<<"\t********=======MENU=======********\n";
cout<<"\t** Tack A for record data
cout<<"\t** Tack B for binary_search

**\n";
**\n";

cout<<"\t** Tack C for linear search

**\n";

cout<<"\t** Tack D for selection_sort

**\n";

cout<<"\t** Tack E for insertiion_sort **\n";


cout<<"\t** Tack F for bubble sort

**\n";

cout<<"\t** Tack G to see group members **\n";


cout<<"\t** Tack H for exit program

**\n";

cout<<"\t********==============************\n";

cout<<"\n\t\t Enter your choise\t\t\n";


char choice; a:cin>>choice; switch(choice){
case 'A': case 'a':Record_data();break;
case 'B':case 'b':Binary_search();break;
case 'C':case 'c':Linear_search();break;
case 'D':case 'd':Selection_sort();break;
case 'E': case 'e':Insertion_sort();break;
case 'F':case 'f':Bubble_sort();break;
case 'G':case 'g':Group_members();break;
case 'H': case 'h':
cout<<"\t\n\t========****** Thank You For All! *****=========";
cout<<"\t\n\t======**********
********=========";return 0;

FINISHED!!!

default:cout<<"Please enter approprate choice:"; goto a; }


cout<<"\n\nPress 0 To Go To Main Menu:";
int f; b:cin>>f; if(f==0) goto w;else{
cout<<"Please Enter Approprate Choice:"; goto b; }}
char Binary_search(){ if(cheack==0) {
cout<<"Frist You Must Record Employ Status (Data)Befor You Going To
Do?\n"; return 0; } else{
employ_status local[100];
for(int g=0;g<n;g++) {
strcpy(local[g].name,em[g].name);
strcpy(local[g].birth_p,em[g].birth_p);
strcpy(local[g].birth_d,em[g].birth_d);
strcpy(local[g].id,em[g].id);
local[g].salary=em[g].salary;}

int cmp,loc,min,mid,max; char temp[50];


cout<<"\nWelcome to Binary_search!\n";
cout<<"\nThe Data That You Enterd Is:\n";
for (output=0; output < n; output++){
cout<<endl<<"Name\tID\tSalary\tBirth_Place\tBirth_Date\t\n";
for (output=0; output < n; output++){
cout << local[output]. name <<"\t";
cout << local[output]. id

<<"\t";

cout << local[output].salary <<"\t";


cout << local[output].birth_p <<"\t\t";
cout << local[output].birth_d <<"\t\t";
cout<<setw(4) ;cout<<endl; } }
cout<<"\nEnter search name:"; cin>>temp;
min=0; max=n-1; loc=-1;
while((min<=max)&&(loc==-1)) {
mid=(min+max)/2;
cmp=strcmp(temp,local[mid].name);
if(cmp==0)loc=mid;
else if(cmp<0)max=mid-1;
else min=mid+1; } if(loc==-1)
cout<<"The data that you entered is not found in your list";else
cout<<"The data that you entered is found at location: "<<(loc); return 0;}}
char Linear_search(){ if(cheack==0) {
cout<<"Frist You Must Record Employ Status (Data)Befor You Going To Do?\n";
return 0; } else {
employ_status local[100];
for(int g=0;g<n;g++){

strcpy(local[g].name,em[g].name);
strcpy(local[g].birth_p,em[g].birth_p);
strcpy(local[g].birth_d,em[g].birth_d);
strcpy(local[g].id,em[g].id);
local[g].salary=em[g].salary;}
int cmp,k=0;
cout<<"\nWelcome to Linear_Search!\n";
cout<<"\nThe data that you recorded is:\n";
for (output=0; output < n; output++){
cout<<endl<<"Name\tID\tSalary\tBirth_Place\tBirth_Date\t\n";
for (output=0; output < n; output++){
cout << local[output]. name <<"\t";
cout << local[output]. id

<<"\t";

cout << local[output].salary <<"\t";


cout << local[output].birth_p <<"\t";
cout << local[output].birth_d <<"\t\t";
cout<<setw(4)<<"\t";cout<<endl;} }
char temp[50]; cout<<"\nEnter search name:"; cin>>temp;
for(int i=0;i<n;i++) {
cmp=strcmp(temp,local[i].name);if(cmp==0){ k++;
cout<<"The data that you entered is found at index: "<<i<<endl;}}if(k==0)
cout<<"The data that you entered is not found in the list";return 0; }}
char Selection_sort(){if(cheack==0){
cout<<"Frist You Must Record Employ Status (Data)Befor You Going To Do?\n";
return 0;} else{
employ_status local[100];

for(int g=0;g<n;g++){
strcpy(local[g].name,em[g].name);
strcpy(local[g].birth_p,em[g].birth_p);
strcpy(local[g].birth_d,em[g].birth_d);
strcpy(local[g].id,em[g].id);
local[g].salary=em[g].salary;}
cout<<"\nWelcome to Selection_Sort!\n";
cout<<"\nThe data that you recorded is:\n";
cout<<endl<<"Name\tID\tSalary\tBirth_Place\tBirth_Date\t\n";
for (output=0; output < n; output++){
cout << local[output].name << "\t";
cout << local[output].id <<"\t";
cout << local[output].salary << "\t";
cout << local[output].birth_p << "\t\t";
cout << local[output].birth_d << "\t\t";
cout<<setw(4)<<"\t";cout<<endl; }
int min; int cmp; char sortName[50]; char b_place[40];char b_date[20]; char
i[10]; double sal;
for (int start = 0; start <( n - 1); start++ ) { min = start;
strcpy(sortName,local[start].name );
strcpy(b_place,local[start].birth_p );
strcpy(b_date,local[start].birth_d);
strcpy(i,local[start].id);
sal=local[start].salary;
for (int inner = (start+1); inner < n; inner++){
cmp=strcmp(local[inner].name,sortName);if (cmp<0){
strcpy(sortName,local[inner].name );

strcpy(b_place,local[inner].birth_p);
strcpy(b_date,local[inner].birth_d);
strcpy(i,local[inner].id);
sal=local[inner].salary; min = inner;} }
strcpy(local[min].name,local[start].name);
strcpy(local[min].birth_p,local[start].birth_p);
strcpy(local[min].birth_d,local[start].birth_d);
strcpy(local[min].id,local[start].id);
local[min].salary=local[start].salary;
strcpy(local[start].name,sortName);
strcpy(local[start].birth_p,b_place);
strcpy(local[start].birth_d,b_date);
strcpy(local[start].id,i);
local[start].salary=sal;}
cout<<"\nBy using Selecion_Sort the sorted data are:\n";
cout<<endl<<"Name\tID\tSalary\tBirth_Place\tBirth_Date\t\n";
for (output=0; output < n; output++){
cout << local[output]. name <<"\t";
cout << local[output]. id

<<"\t";

cout << local[output].salary <<"\t";


cout << local[output].birth_p <<"\t\t";
cout << local[output].birth_d <<"\t\t";cout<<endl;} return 0;}}
char Insertion_sort(){ if(cheack==0)
{cout<<"Frist You Must Record Employ Status (Data) Befor You Going To Do?\n";
return 0;} else {
employ_status local[100];
for(int g=0;g<n;g++) {

strcpy(local[g].name,em[g].name);
strcpy(local[g].birth_p,em[g].birth_p);
strcpy(local[g].birth_d,em[g].birth_d);
strcpy(local[g].id,em[g].id);
local[g].salary=em[g].salary; }
int cmp; char nme[50]; char bp[40]; char bd[20]; char i[10]; double sal;
cout<<"\nWelcome to Insertion_Sort!\n";
cout<<endl<<"Name\tID\tSalary\tBirth_Place\tBirth_Date\t\n";
for (output=0; output < n; output++) {
cout << local[output].name << "\t";
cout << local[output].id <<"\t";
cout << local[output].salary << "\t";
cout << local[output].birth_p << "\t\t";
cout << local[output].birth_d << "\t\t";
cout<<setw(4)<<"\t";cout<<endl;}
for(int start=0;start<n;start++){
for(int inner=0;inner<start;inner++){
cmp=strcmp(local[inner].name,local[start].name);if(cmp>0){
strcpy(nme,local[inner].name);
strcpy(bp,local[inner].birth_p);
strcpy(bd,local[inner].birth_d);
strcpy(i,local[inner].id);
sal=local[inner].salary;
strcpy(local[inner].name,local[start].name);
strcpy(local[inner].birth_p,local[start].birth_p);
strcpy(local[inner].birth_d,local[start].birth_d);

strcpy(local[inner].id,local[start].id);
local[inner].salary=local[start].salary;
for(int k=start;k>inner;k--){
strcpy(local[k].name,local[k-1].name);
strcpy(local[k].birth_p,local[k-1].birth_p);
strcpy(local[k].birth_d,local[k-1].birth_d);
strcpy(local[k].id,local[k-1].id);
local[k].salary=local[k-1].salary;}
strcpy(local[k+1].name,nme);
strcpy(local[k+1].birth_p,bp);
strcpy(local[k+1].birth_d,bd);
strcpy(local[k+1].id,i);
local[k+1].salary=sal;} }}
cout<<"\nBy using Insertion_sort the sorted data are:\n";
cout<<endl<<"Name\tID\tSalary\tBirth_Place\tBirth_Date\t\n";
for (output=0; output < n; output++) {
cout << local[output].name << "\t";
cout << local[output].id <<"\t";
cout << local[output].salary << "\t";
cout << local[output].birth_p << "\t\t";
cout << local[output].birth_d << "\t\t";cout<<endl; }return 0; }}
char Bubble_sort(){ if(cheack==0)
{ cout<<"Frist You Must Record Employ Status (Data) Befor You Going To Do?\n";
return 0; } else {
employ_status local[100];
for(int g=0;g<n;g++) {

strcpy(local[g].name,em[g].name);
strcpy(local[g].birth_p,em[g].birth_p);
strcpy(local[g].birth_d,em[g].birth_d);
strcpy(local[g].id,em[g].id);
local[g].salary=em[g].salary; }
int start,inner,cmp;
char nme[50]; char bp[40]; char bd[20]; char i[10]; double sal;
cout<<"\nWelcome to Bubble_Sort!\n";
cout<<"\nThe data that you recorded is:\n";
cout<<endl<<"Name\tID\tSalary\tBirth_Place\tBirth_Date\t\n";
for (output=0; output < n; output++){
cout << local[output].name << "\t";
cout << local[output].id <<"\t\t";
cout << local[output].salary << "\t";
cout << local[output].birth_p << "\t\t";
cout << local[output].birth_d << "\t\t";
cout<<setw(4);cout<<endl; }
for(start=0; start<n; start++)
for(inner=0; inner<n-1; inner++) {
cmp=strcmp(local[inner].name,local[inner+1].name);if(cmp>0){
strcpy(nme,local[inner+1].name);
strcpy(bp,local[inner+1].birth_p);
strcpy(bd,local[inner+1].birth_d);
strcpy(i,local[inner+1].id);
sal=local[inner+1].salary;
strcpy(local[inner+1].name,local[inner].name);

strcpy(local[inner+1].birth_p,local[inner].birth_p);
strcpy(local[inner+1].birth_d,local[inner].birth_d);
strcpy(local[inner+1].id,local[inner].id);
local[inner+1].salary=local[inner].salary;
strcpy(local[inner].name,nme);
strcpy(local[inner].birth_p,bp);
strcpy(local[inner].birth_d,bd);
strcpy(local[inner].id,i);
local[inner].salary=sal;} }
cout<<"\nBy using Bubble_Sort the sorted data is:\n";
cout<<endl<<"Name\tID\tSalary\tBirth_Place\tBirth_Date\n";
for (output=0; output < n; output++) {
cout << local[output].name << "\t";
cout << local[output].id <<"\t";
cout << local[output].salary << "\t";
cout << local[output].birth_p << "\t\t";
cout << local[output].birth_d << "\t";cout<<endl;} return 0;}}
char Record_data(){
cout<<"\n\tRecord Your Data\n ";
cout<<"How Many Data Do You Went To Record:"; cin>>n;
for( cheack;cheack<n;cheack++) {
cout<<" Enter name::"; cin>>em[cheack].name;
cout<<" Enter birth place::"; cin>>em[cheack].birth_p;
cout<<" Enter salary::";cin>>em[cheack].salary;
cout<<" Enter birth date::";cin>>em[cheack].birth_d;
cout<<" Enter id::"; cin>>em[cheack].id; }

cout<<"You Will Enterd The Data Succesfuly,so go to main menu and do any thing
that you want\n"; return 0;}
char Group_members(){
cout<<"\t@@@@@@@@@@@@@ WOLLEGA UNIVERSITY
@@@@@@@@@@@@@@\n";
cout<<"\t@@ COLLEGE OF ENGINEERING AND TECHINOLOGY
cout<<"\t@@ DEPARTMENT OF INFORMATICS

@@\n";

@@\n";

cout<<"\t@@ PROGRAM OF INFORMATIN TECHINOLOGY

@@\n";

cout<<"\t@@ DATA STRUCTURE AND ALGORTHIM GROUP PROJECT @@\n";


cout<<"\t@@ YEAR II\tSEC 'A'

@@\n";

cout<<"\t\t GROUP III\n";


cout<<"\n\t******---Group Members---*******\n";
cout<<"\n\tName\t\t
cout<<"\n\t----\t\t

ID";
--\n";

student_name no[7];
strcpy(no[1].name,"Ambelu Getnet

");

strcpy(no[1].id,"1470/14");
strcpy(no[2].name,"Hasen Alifnur

");

strcpy(no[2].id,"1631/14");
strcpy(no[3].name,"Wandhibne Temesgen");
strcpy(no[3].id,"1772/14");
strcpy(no[4].name,"Tsiga Fufa

");

strcpy(no[4].id,"1764/14");
strcpy(no[5].name,"Mekdes Asresahegn ");
strcpy(no[5].id,"1682/14");
for(int i=1;i<6;i++)
cout<<i<<","<<no[i].name<<"----------"<<no[i].id<<endl;

cout<<"\n\n\n\t submtion date:\n\t 05/05/2016";


cout<<"\t\t\t Submitted to:\n\t\t\t\t\t\tInstrutor Kemal"; return 0;}