Created
May 11, 2018 17:06
-
-
Save edenizk/967393e7f00d29debe584b43c6cc7b9b to your computer and use it in GitHub Desktop.
structures
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
using namespace std; | |
/* run this program using the console pauser or add your own getch, system("pause") or input loop */ | |
/* | |
int length ( char s [] ){ | |
int i=0; | |
for(; s[i]!='\0';i++); | |
return i; | |
} | |
void reverse (char s []){ | |
for(int i=length(s);i>=0;i--){ | |
cout<<s[i]; | |
} | |
} | |
void reverse2 (char s[]){ | |
int l=0,r =length(s)-1; | |
while (l<r) | |
{ | |
char temp = s[l]; | |
s[l]=s[r]; | |
s[r]=temp; | |
l++;r--; | |
} | |
} | |
/* | |
string reverse3 (string s){ | |
int l=0,r; | |
r =(s.length-1) | |
while (l<r) | |
{ | |
char temp = s.at[l]; | |
s[l]=s[r]; | |
s[r]=temp; | |
l++;r--; | |
} | |
return s; | |
}*/ | |
struct value | |
{ | |
string first,last ; | |
char gender; | |
int age; | |
}; | |
void reading(value &b) | |
{ | |
cout<<"first name :\n"; | |
cin>>b.first; | |
cout<<"last name : \n"; | |
cin>>b.last; | |
cout<<"gender [F/M]: \n"; | |
cin>>b.gender; | |
cout<<"age :\n"; | |
cin>>b.age; | |
} | |
void writing(int i, value b[]) | |
{ | |
for(int j=0;j<i;j++) | |
{ | |
cout<<"///////////////////\n"<<j+1<<" - "<<"first name : "<<b[j].first<<endl<<"last name : "<<b[j].last<<endl | |
<<"gender : "<<b[j].gender<<endl<<"age : "<<b[j].age<<endl<<"/////////////////"<<endl; | |
} | |
} | |
int main(int argc, char** argv) { | |
/* | |
char text[20]; | |
cout<<"Enter The text\n"; | |
//scanf("%s", s); | |
cin>>text; | |
cout<<"lenght of "<<text<<" is "<<lenght(text)<<endl<<"reverse1 "; | |
//reverse(text); | |
cout<<endl; | |
reverse2(text); | |
cout<<"reverse2 of "<<text<<" is "<<endl; | |
*/ | |
//strings | |
/* | |
string text; | |
cout<<"enter the text\n"; | |
cin>>text; | |
getline( cin, text); | |
cout<<"lenght of "<<text<<" is "<<text.length()<<endl<<"reverse1 "; | |
reverse3(text);*/ | |
//Structures | |
value a[100]; | |
bool again=1; | |
int choose=0,i=0; | |
do{ | |
cout<<"1-add a person\n2-list all people\n3-finish\nselect the option:"; | |
cin>>choose; | |
cout<<endl; | |
if(choose==1) | |
{ | |
reading(a[i]); | |
system("pause"); | |
system("cls"); | |
i++; | |
} | |
else if(choose==2) | |
{ | |
writing(i,a); | |
system("pause"); | |
system("cls"); | |
} | |
}while(choose!=3&&i<100); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment