Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- using namespace std;
- int main()
- {
- typedef struct
- {
- string firstName;
- string lastName;
- string phone;
- } StRec;
- StRec str[10];
- string input, input1, input2,input3;
- int count = 0;
- while(cin>>input)
- {
- if (input == "print")
- {
- if (count == 0)
- {
- cout << "Print Error\n";
- }
- else
- {
- for(int i=0;i<=count;i++)
- {
- if(str[i].firstName == "")
- {
- continue;
- }
- cout << str[i].firstName << "\t" << str[i].lastName << "\t" << str[i].phone<<"\n";
- }
- }
- }
- else if (input =="insert")
- {
- if(count == 10)
- {
- cout << "Insert Error\n";
- }
- else
- {
- cin >> input1;
- cin >> input2;
- cin >> input3;
- str[count].firstName = input1;
- str[count].lastName = input2;
- str[count].phone = input3;
- cout << str[count].firstName << "\t" << str[count].lastName << "\t" << str[count].phone << "\n";
- count++;
- }
- }
- else if (input == "search")
- {
- bool flag = false;
- cin >> input1;
- cin >> input2;
- cin >> input3;
- for (int i=0 ; i<= count ; i++)
- {
- if (str[i].firstName == input1 &&
- str[i].lastName == input2 &&
- str[i].phone == input3)
- {
- cout<<i<<endl;
- flag = 1;
- }
- }
- if (flag == false)
- {
- cout << "Search Error\n";
- }
- }
- else if (input == "delete")
- {
- bool flag = false;
- cin >> input1;
- cin >> input2;
- cin >> input3;
- for (int i = 0; i <= count; i++)
- {
- if (str[i].firstName == input1 &&
- str[i].lastName == input2 &&
- str[i].phone == input3)
- {
- str[i].firstName = "";
- str[i].lastName = "";
- str[i].phone = "";
- }
- flag = true;
- }
- if (flag == false)
- {
- cout << "Delete Error\n";
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement