First here to talk about the personal experience of the last two months of the program, to the medium-term enthusiasm for a little bit of cooling, especially after the complexity and difficulty of the content of the increase, the individual also has lazy time, a lot of weeks have no progress, very annoying, But here's to the same programmer as me. A beginner says my current chicken blood motto: No end to effort, success is not too far. Come on, everybody!
OK, here is a brief introduction of my small program, is a time for you to read the management and testing procedures, quite simple to use the vector and set the mix, to achieve is a number of loops and judgment statements, the following nonsense does not say the attached code and the results of the operation:
#include "stdafx.h" #include <iostream> #include <string> #include <vector> #include <set># Include <cstdlib> #include <ctime>using namespace Std;int main () {//Here first create a container to deposit the title you want to read in string BookName; vector<string>ivec;cout<< "What books do you want to read this month:" <<endl;while (cin>>bookname) Ivec.push_back ( BookName); size_t num=ivec.size ();//Create a set here, and save the book in set<string>mark;string Choice,bname;bool onemonth=false ; Srand ((unsigned) time (NULL));//Get a random number rand () Cin.clear () in accordance with the system times (!onemonth) && (!ivec.empty ()) { Cin.clear ();cout<< "Do you want to read now?" y/n "<<endl;cin>>choice;if (choice[0]== ' Y ' | | choice[0]== ' Y ') {int i=rand ()%ivec.size ();//This is to set the vector's subscript to random number, let the system randomly recommend a book to us in the vector bname=ivec[i];cout<< "We recommend this book for you to read:" <<endl;cout<<bname<<endl;mark.insert (bname); Ivec.erase (Ivec.begin () +i); cout << "After a week, have you finished reading this book?" y/n "<<endl;cin>>choice;if (choice[0]== ' N ' | | choice[0]== ' N ') {mark.erase (bookname);//This time the book has not been read from the reading of the deleted Ivec.push_bACK (bookname);//deposit into the unread}}cout<< "one months? y/n "<<endl;cin>>choice;if (choice[0]== ' Y ' | | choice[0]== ' y ') onemonth=true;} if (onemonth) {if (!mark.empty ()) {cout<< "This month you read these books:" <<endl;for (Set<string>::iterator iter= Mark.begin (); Iter!=mark.end (); iter++) {cout<<*iter<< "";}} Cout<<endl;if (!ivec.empty ()) {cout<< "This month you still have these books unread:" <<endl;for (Vector<string>::iterator it =ivec.begin (); It!=ivec.end ();) {cout<<*it<< ""; ++it;}} Cout<<endl;if (Mark.size () ==num) cout<< "to force! Read all the books, really genius! ";} System ("pause"); return 0;}
Like me the vast number of beginners, adhere to!
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Read the Test applet