当前位置: 首页>>代码示例>>C++>>正文


C++ AddressBook::printPreview方法代码示例

本文整理汇总了C++中AddressBook::printPreview方法的典型用法代码示例。如果您正苦于以下问题:C++ AddressBook::printPreview方法的具体用法?C++ AddressBook::printPreview怎么用?C++ AddressBook::printPreview使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在AddressBook的用法示例。


在下文中一共展示了AddressBook::printPreview方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: DETAILED


//.........这里部分代码省略.........

/////////////////////
//MAIN OPTION BLOCK//
/////////////////////
 string option;
 //option is the variable for the menu option input from the user
 do{ //this do loop will run wile the option is not Q or q for quit.
    do{ //this do loop will run until a valid option is received from the user.
        displayMenu();
        cout << "Select an option:";
        cin >> option;
        //if the option is longer than 1 character. (can probably leave out >1 as function checks for length also)
        if(checkOption(option)==false || option.length()>1)
        {
            cout << "Invalid choice please try again.." << endl; //output invalid choice statement.
        }
    }while(checkOption(option)==false);

    //Program will get here only if option is valid.
    //Options are listed in order shown on project 3 description

        //////////////////////////////
        //OPTION [A] - Add a contact//
        //////////////////////////////
    if(option=="A" || option=="a")
    {
        //Function A uses push_back to add the new contact
        //Check AddressBook header/source file for more detail.
        bookOne.functionA();

        //if the new added push_back vector is valid (NOTE* if valid this function will NOT delete)
        if(bookOne.contactValidate(bookOne.vectorSize()-1)==1)
        {
            //Thus print detail should print the last entry added which is vector size-1;
            bookOne.printDetail(bookOne.vectorSize()-1);
            cout << "\n**New contact added to the end of the list at position " << bookOne.vectorSize()-1 << endl;
        }

        else //no need to call function again as the first if statement already called it and will delete if it's invalid.
        {    //will enter this else if it's deleted, in that case output the error message below.
            cout <<"\nInvalid contact..."
                 <<"\nPlease input valid/non space leading values for the first four fields." << endl;
        }
    }

        //////////////////////////////////////////
        //OPTION [D] - Display by sorted contact//
        //////////////////////////////////////////
    else if(option=="D" || option=="d")
    {
        //sort is the token # which it needs to be sorted by. (1-4 only)
        int sort=0;

        //do-while loop will run until a valid token choice is given.
        do{
            cout << "\nWhich field would you like to sort by?"
                << "\n1)Last Name"
                << "\n2)First Name"
                << "\n3)Nickname"
                << "\n4)Email 1"
                << "\n--------------"
                << "\nEnter Choice:";
            cin  >> sort;

            //if statement to reprompt user for valid choice
            if(sort<=0 || sort > 4)
            {
                cout << "**Error choice input, please enter choice 1-4." << endl;
            }
        }while(sort<=0 || sort > 4);

        //functionD sorts the contacts accordint to token sort
        //I used the same sorting method as my project 2!! =)
        //More in detail in AddressBook header/source file
        bookOne.functionD(sort);

        //Print preview the newly sorted contacts
        bookOne.printPreview();
    }

        ///////////////////////////////////////////
        //OPTION [C] - Display details of contact//
        ///////////////////////////////////////////
    else if(option=="C" || option=="c")
    {
        //Simply print out the details of the desired contact entry.
        int entry=0;
        bookOne.printPreview();
        do{//do-while loop to keep the entry selection within bounds of the valid vector.
            cout << "Which entry # would you like to view in detail?:";
            cin >> entry;
            if(entry<0 || entry>bookOne.vectorSize()-1)
            {
                cout << "\n**Error entry #, please try again.." << endl;
            }
        }while(entry<0 || entry>bookOne.vectorSize()-1);
        //printDetail will print the details of the desired entry.
        bookOne.printDetail(entry);

    }
开发者ID:helloye,项目名称:HunterCSCI,代码行数:101,代码来源:paing_main.cpp


注:本文中的AddressBook::printPreview方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。