- 1,
- #include <iostream>
- #include <string>
- #include <cctype>
- int main()
- {
- std::string inputStr;
- std::cout<<"Enter your character list. enter @ to end." <<std::endl;
- char ch;
- std::string srcStr;
- std::string dstStr;
- while(std::cin.get(ch))
- {
- if(ch == '@')
- {
- std::cout << "input befor exchane:" << srcStr << std::endl;
- std::cout << "input after exchane:" << dstStr << std::endl;
- break;
- }
- srcStr = srcStr + ch;
- if(islower(ch))
- {
- dstStr = dstStr + char(toupper(ch));
- continue; // 必须有 continue, 否则全转为小写了
- }
- if(isupper(ch))
- {
- dstStr = dstStr + char(tolower(ch));
- continue;
- }
- dstStr = dstStr + ch; // 其他字符原样显示
- }
- return 0;
- }
- 2,
- #include <iostream>
- #include <array>
- int main()
- {
- const int size = 10;
- std::array<double,size> donation;
- double sum = 0.0;
- double avrgValue = 0.0;
- int countLager = 0;
- int enterNum = 0;
- std::cout<<"Pleas enter up 10 double value, Non-digital to exit."<<std::endl;
- while((enterNum <size) && (std::cin>>donation[enterNum]))
- {
- sum += donation[enterNum];
- enterNum++;
- }
- avrgValue = sum/enterNum;
- for(int i=0; i<enterNum;i++)
- {
- if(donation[i]> avrgValue)
- {
- countLager++;
- }
- }
- std::cout<<"There have" <<countLager << "larger than everage." << std::endl;
- return 0;
- }
- 3,
- #include <iostream>
- #include <string>
- void useage()
- {
- std::cout<<"Please enter one of the following choices:"<<std::endl;
- std::cout<<"c) carnivore\t"<<"p) pianist"<<std::endl;
- std::cout<<"t) tree\t\t"<<"g) game"<<std::endl;
- }
- void tip()
- {
- std::cout<<"Please enter a c, p, t or g:";
- }
- int main()
- {
- useage();
- char ch;
- while(true)
- {
- std::cin>>ch;
- if(ch != 'c' && ch != 'p' && ch != 't' && ch != 'g')
- {
- tip();
- continue;
- }
- if(ch == 'c')
- {
- std::cout<<"A tager is a carnivore." << std::endl;
- continue;
- }
- if(ch == 'p')
- {
- std::cout<<"Beethoven is a pianist." << std::endl;
- continue;
- }
- if(ch == 't')
- {
- std::cout<<"A maple is a tree." << std::endl;
- continue;
- }
- if(ch == 'g')
- {
- std::cout<<"Chess is a game." << std::endl;
- continue;
- }
- }
- return 0;
- }
来源: http://www.bubuko.com/infodetail-2733557.html