Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Example program
- #include <iostream>
- #include <string>
- using namespace std;
- int main() {
- int i, k;
- string names[99];
- int lengthOfNames = 0;
- string name, choice;
- bool found;
- do {
- cout<<"Insert a name (or press 'finish' to proceed)> ";
- cin>>name;
- if (name != "finish") {
- names[lengthOfNames] = name;
- lengthOfNames++;
- }
- }
- while(name!="finish");
- cout<<"1) See all names"<<endl<<"2) Search by name"<<endl<<"3) Select all after certain name"<<endl<<"4) Select all before certain name"<<endl<<"5) Change a name"<<endl;
- cout<<"What do you want to do?"<<endl;
- cin>>choice;
- if (choice == "1") for (i=0; i<lengthOfNames; i++) cout<<names[i]<<endl;
- if (choice == "2") {
- cout<<"Insert a name:";
- cin>>name;
- found = false;
- for (i=0; i<lengthOfNames; i++) {
- if (names[i] == name) {
- found = true;
- break;
- }
- }
- cout<<"Position: "<<i<<endl;
- }
- if (choice == "3") {
- cout<<"Insert a name:";
- cin>>name;
- found = false;
- for (i=0; i<lengthOfNames; i++) {
- if (names[i] == name) {
- found = true;
- break;
- }
- }
- cout<<"Position: "<<i<<endl;
- for (k=i+1; k<lengthOfNames; k++) cout<<names[k]<<endl;
- }
- if (choice == "4") {
- cout<<"Insert a name:";
- cin>>name;
- found = false;
- for (i=0; i<lengthOfNames; i++) {
- if (names[i] == name) {
- found = true;
- break;
- }
- }
- cout<<"Position: "<<i<<endl;
- for (k=0; k<i; k++) cout<<names[k]<<endl;
- }
- if (choice == "5") {
- cout<<"Insert a name:";
- cin>>name;
- found = false;
- for (i=0; i<lengthOfNames; i++) {
- if (names[i] == name) {
- found = true;
- cout<<"Insert the new name: ";
- cin>>name;
- names[i] = name;
- cout<<"Done! The new name is "<<name<<" and the position is "<<i<<endl;
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement