コード例 #1
0
ファイル: fileio.cpp プロジェクト: jokerlee/college
void
FileIO::read(PhoneBook & pb)
{
    ifstream fin("a.txt");
    string buf;
    int count;

    vector<string> fields;
    fin >> count; fin.get();
    for (int i=0; i<count; ++i)
    {
        getline(fin, buf);
        fields.push_back(buf);
    }
    pb.setFields(fields);

    fin >> count;fin.get();
    Record newrec(pb);
    for (int i=0; i<count; ++i)
    {
        fin >> newrec;
        fin.get();
        pb.addRecord(newrec);
    }

    fin.close();
}
コード例 #2
0
ファイル: cmd_interface.cpp プロジェクト: jokerlee/college
void
CmdInterface::onDelRecord(PhoneBook & pb)
{
    long index=-1;
    Record tmp;
    println("Input the record's index to delete(0 to cancel):");
    if ((index = getNumber()) != 0)
    {
        if (tmp = pb.searchByIndex(index))
        {
            println("The record is: ");
            show(tmp);
            println("Are you sure to delete it? (y/n)");
            if (getConfirmed())
            {
                pb.delRecord(index);
                cout << "Record successfully deleted.\n";
            }
            else
                println("Canceled");
        }
        else
            println("Index not found!");
    }
    else
        println("Canceled");
            

}
コード例 #3
0
ファイル: Source.cpp プロジェクト: zVoxty/University
int main() {

	PhoneBook phoneBook;
	Contacts contact;

	bool ProgramOn = true;
	int option;

	while (ProgramOn) {
		Intro();
		cin >> option;
		cout << endl;
		switch (option)
		{
		case 1:
			cout << "Insert contact data : \n ";
			contact.getData(phoneBook);
			phoneBook.contacts.push_back(contact);
			break;
		case 2: {
			string contactName;
			cout << "Insert contact name : ";
			cin >> contactName;

			if (checkIfExist(phoneBook, contactName) != -1) {
				phoneBook.contacts[checkIfExist(phoneBook, contactName)].showContact();
			}
			else {
				cout << "Contact " << contactName << " doesn't exist !\n";
			}
		}
			break;
		case 3: {
			string contactName;
			cout << "\n Contacts in phoneBook : "<< phoneBook.getContactNumbers() <<"\n";
			for (int i = 0; i < phoneBook.contacts.size(); i++)
			{
				cout << phoneBook.contacts[i].getContactName();
				cout << "\n\n";
			}
		}
			break;
		case 4:
			ProgramOn = false;
			break;
		default:
			cout << "Wrong option ! ";
			break;
		}
	}

	system("PAUSE");
}
コード例 #4
0
ファイル: Soln10_06.cpp プロジェクト: ktjones/BVC2010
int main()
{  
  PhoneBook phonebook;
  char answer = 0;

  while(true)
  {
    cout << "Do you want to enter a phone book entry(Y or N): " ;
    cin >> answer;
    cin.ignore();                      // Ignore newline in buffer
    if(toupper(answer) == 'N')
      break;
    if(toupper(answer) != 'Y')
    {
      cout << "Invalid response. Try again." << endl;
      continue;
    }
    phonebook.addEntry();
  }

  // Query the phonebook
  while(true)
  {
    cout << endl << "Choose from the following options:" << endl
         << "A  Add an entry   D Delete an entry for a name   G  Get entries for a name" << endl
         << "L  List entries   d Delete an entry for a number g  Get entries for a number" << endl
         << "Q  Quit" << endl; 
    cin >> answer;
    cin.ignore();                      // Ignore newline in buffer
    
    switch(answer)
    {
    case 'A': case 'a':
        phonebook.addEntry();
        break;
      case 'G':
        phonebook.getNumber();
        break;
      case 'g':
        phonebook.getName();
        break;
      case 'D':
        phonebook.deleteNameEntry();
        break;
      case 'd':
        phonebook.deleteNumberEntry();
        break;
      case 'L': case 'l':
        phonebook.listEntries();
        break;
      case 'Q': case 'q':
        return 0;
      default:
        cout << "Invalid selection. Try again." << endl;
        break;
    }
  }
  return 0;
}
コード例 #5
0
ファイル: cmd_interface.cpp プロジェクト: jokerlee/college
void
CmdInterface::onEditRecord(PhoneBook & pb)
{
    long index = -1;
    Record tmp;
    println("Input the record's index to Edit(0 to cancel):");
    if ((index = getNumber()) != 0)
    {
        if (tmp = pb.searchByIndex(index))
        {
            println("The record is: ");
            show(tmp);
            edit_menu();
            char cmd;
            do{
                cmd = getCommand();
                switch (cmd)
                {
                    case '1': 
                        println("Input the new name:");
                        tmp.setName(getLine());
                        println("Name successfully modified.");
                        break;

                    case '2': 
                        println("Input the new phone:");
                        tmp.setPhone(getLine());
                        println("Phone successfully modified.");
                        break;

                    case '3': 
                        println("Input the new address:");
                        tmp.setAddr(getLine()); 
                        println("Address successfully modified.");
                        break;
                    case '0': println("Finish Modification."); break;
                    default : println("Error Command!"); break;
                }
                edit_menu();
            }while (cmd != '0');
            pb.setRecord(index, tmp);
            cout << "Record #" << index << " successfully modified." << endl;
        }
        else
            println("Index not found!");
    }
    else
        println("Canceled"); 
}
コード例 #6
0
ファイル: main.cpp プロジェクト: rsadhu/work
int  main(void)
{
    PhoneBook *pbook = new PhoneBook(FILETYPE);
    Contact *c = new Contact("rakesh","sadhu","9686862367","9966680427");
    pbook->addContact(c);
    QVector<Contact *>*list = pbook->findContacts("rakesh");
    Contact *o;
    int i=-1;
    while(++i<list->size())
    {
        o = list->at(i);
        qDebug()<<"\nname :: "<<o->fname<<"\nsurname ::"<<o->lname<<"\nmob:: "<<o->mob<<"\n tele"<<o->landline<<endl;
    }
    delete pbook;
    return 0;
}
コード例 #7
0
void DbusAdapter::_phoneCall(QDBusMessage msg) {
    qDebug() << "Got phone call dbus message:" << msg;

    QDBusArgument *arg = (QDBusArgument *) msg.arguments().at(1).data();

    if (arg->currentType() == QDBusArgument::MapType) {
        QMap<QString, QString> argMap = unpackMessage(*arg);

        qDebug() << "Extracted argument map:" << argMap;

        if (argMap.value("State") == "incoming") {
            PhoneBook phonebook;
            emit phoneCall(argMap.value("LineIdentification"), phonebook.NameByPhoneNumber(argMap.value("LineIdentification")));
        }
    }
}
コード例 #8
0
ファイル: fileio.cpp プロジェクト: jokerlee/college
void
FileIO::store(const PhoneBook & pb)
{
    ofstream fout("a.txt");
    
    if (!fout) throw FileException("a.txt");

    fout << pb.recSize() << endl;
    for (int i=0; i<pb.recSize(); ++i)
        fout << pb.field(i) << endl;

    fout << pb.size() << endl;
    cListIter i=pb._records.begin();
    for ( ; i!=pb._records.end(); ++i)
        fout << *i << endl;
}
コード例 #9
0
ファイル: main.cpp プロジェクト: y0ja/CPP_Pool
int		main(void)
{
	bool		end = false;
	PhoneBook	PhoneBook;
	std::string	str;

	while (end == false) {
		std::cout << "What do you want? (ADD, SEARCH, EXIT) : ";
		std::getline(std::cin, str);
		str_toupper(&str);
		if (str.compare("ADD") == 0)
			PhoneBook.addContact();
		else if (str.compare("SEARCH") == 0)
			PhoneBook.search();
		else if (str.compare("EXIT") == 0)
			end = true;
		else
			std::cout << "[" << str << "]" << " is invalid input." << std::endl;
	}
	return (0);
}
コード例 #10
0
ファイル: cmd_interface.cpp プロジェクト: jokerlee/college
void
CmdInterface::onSearchRecord(PhoneBook & pb)
{
    println("(1)Search index (2)Search name (3)Search phone");
    char cmd;
    cmd = getCommand();
    switch(cmd)
    {
        case '1':
            long index;
            println("Input the index to search:");
            if ((index = getNumber()) != 0)
            {
                Record tmp;
                if (tmp = pb.searchByIndex(index))
                {
                    show(tmp);
                }
                else
                    println("Index not found!");
            }
            else
                println("Canceled");
            break;

        case '2':
            println("Input the name to search:");
            show(pb.searchByName(getLine()));
            break;

        case '3':
            println("Input the phone to search:");
            show(pb.searchByPhone(getLine()));
            break;

        case '0': println("Canceled"); break;
        default : println("Error command."); break;
    }
}
コード例 #11
0
ファイル: cmd_interface.cpp プロジェクト: jokerlee/college
void
CmdInterface::onAddRecord(PhoneBook & pb)
{
    Record newrec("");
    string tmp;
    println("Input the person's name:");
    newrec.setName(getLine());
    println("Input the phone number:");
    newrec.setPhone(getLine());
    println("Input the address:");
    newrec.setAddr(getLine());

    pb.addRecord(newrec);
    println("Record successfully added.");
}
コード例 #12
0
ファイル: cmd_interface.cpp プロジェクト: jokerlee/college
void
CmdInterface::addRecord(PhoneBook & pb)
{
    Record newrec("");
    string tmp;
    cin.ignore();
    cout << "Input the person's name:" << endl;
    newrec.setName((getline(cin, tmp), tmp));
    cout << "Input the phone number:" << endl;
    newrec.setPhone((getline(cin, tmp), tmp));
    cout << "Input the address:" << endl;
    newrec.setAddr((getline(cin, tmp), tmp));

    pb.addRecord(newrec);
    cout <<"Record successfully added.\n";
}
コード例 #13
0
void LookupEntry(const PhoneBook& pb) 
{
      string last, first, phone;
	  cout << "Enter last name: ";
	  cin >> last;
      cout << "Enter first name: ";
	  cin >> first;
	  bool success = pb.Lookup(last, first, phone);
	  if (success) 
	  {
		  cout << "\nThe phone number is " << phone << ". \n";
	  } 
	  else 
	  {
		  cout << "\nError: no one by this name is in the phone book.\n";
	  }
}
コード例 #14
0
void DeleteEntry(PhoneBook& pb) 
{
	string last, first, phone;
	cout << "Enter last name: ";
	cin >> last;
    cout << "Enter first name: ";
	cin >> first;
	bool success = pb.Delete(last, first);
	if (success) 
	{
		cout << "\nDeleted from the phone book.\n";
	}
	else 
	{
		cout << "\nError: no one by this name in the phone book.\n";
	}
}
コード例 #15
0
void AddEntry(PhoneBook& pb) 
{
	string last, first, phone;
	cout << "Enter last name: ";
	cin >> last;
	cout << "Enter first name: ";
	cin >> first;
	cout << "Enter phone: ";
	cin >> phone;
	bool success = pb.Insert(last, first, phone);
	if (success) 
	{
		cout << "\nAdded to the phone book.\n";
	}
	else 
	{
		cout << "\nError: a person with this name is already in the phone book.\n";
	}
}
コード例 #16
0
int main(){
	PhoneBook contacts;
	char choice;
	Help();
	do 
	{
		cout << "Enter command: ";
		cin >> choice;
		switch (choice) 
		{
			case 'a':
			case 'A':
				AddEntry(contacts);
				break;
			case 'd':
			case 'D':
				DeleteEntry(contacts);
				break;
			case 'h':
			case 'H':
				Help();
				break;
			case 'l':
			case 'L':
				LookupEntry(contacts);
				break;
			case 'p':
			case 'P':
				cout << "\n" << contacts;
				break;
			case 'q':
			case 'Q':
				cout << "\nExiting command block.\n";
				break;
			case 'n':
			case 'N':
				cout << "\nNumber of names in the phone book: "
					 << contacts.Size() << endl;
				break;
			default:
				cout << "Invalid command.\n";
			    break;
		}
		cout << "\n";
	}
	while (choice != 'q' && choice != 'Q');
 
	//  The next block tests the destructor
	{
		PhoneBook copy1 = contacts;  // tests copy constructor
		cout << "The copy constructor produces a list with "
			<< copy1.Size() << " elements:\n";
		cout << copy1;

		PhoneBook copy2;
		copy2 = contacts;    // tests assignment operator
		cout << "\nThe assignment operator produces a list with "
			<< copy2.Size() << " elements:\n";
		cout << copy2;

		copy2 = contacts;    // tests assignment operator again
		cout << "\nThe assignment operator produces a list with "
			<< copy2.Size() << " elements:\n";
		cout << copy2;
	}
	cout << "\nThe destructor call was apparently successful.\n";
	return 0;
}