1.
1#include <iostream>2#include <string>3#include <cctype>4 5 intMain ()6 {7STD::stringInputstr;8std::cout<<"Enter your character list. Enter @ to end."<<Std::endl;9 Charch;TenSTD::stringSrcstr; OneSTD::stringDststr; A while(Std::cin.Get(CH)) - { - if(ch = ='@') the { -Std::cout <<"input befor exchane:"<< Srcstr <<Std::endl; -Std::cout <<"input after Exchane:"<< Dststr <<Std::endl; - Break; + } -Srcstr = Srcstr +ch; + if(Islower (CH)) A { atDststr = Dststr +Char(ToUpper (CH)); - Continue;//there must be continue, otherwise it's all lowercase. - } - if(Isupper (CH)) - { -Dststr = Dststr +Char(ToLower (CH)); in Continue; - } toDSTSTR = dststr + ch;//other characters are displayed as-is + } - return 0; the}
2.
1#include <iostream>2#include <array>3 4 intMain ()5 {6 Const intSize =Ten;7std::array<Double,size>donation;8 Doublesum =0.0;9 DoubleAvrgvalue =0.0;Ten intCountlager =0; One intEnternum =0; Astd::cout<<"pleas enter up and double value, non-digital to exit."<<Std::endl; - while((Enternum < size) && (std::cin>>Donation[enternum])) - { theSum + =Donation[enternum]; -enternum++; - } -Avrgvalue = sum/Enternum; + for(intI=0; i<enternum;i++) - { + if(Donation[i] >avrgvalue) A { atcountlager++; - } - } - -std::cout<<"there has"<< Countlager <<"larger than Everage."<<Std::endl; - in return 0; -}
3.
1#include <iostream>2#include <string>3 4 voiduseage ()5 {6std::cout<<"Please enter one of the following choices:"<<Std::endl;7std::cout<<"c) carnivore\t"<<"p) Pianist"<<Std::endl;8std::cout<<"t) tree\t\t"<<"g) Game"<<Std::endl;9 }Ten One voidtip () A { -std::cout<<"Please enter a C, p, t or G:"; - } the intMain () - { - useage (); - Charch; + while(true) - { +Std::cin>>ch; A if(ch! ='C'&& ch! ='P'&& ch! ='T'&& ch! ='g') at { - tip (); - Continue; - } - if(ch = ='C') - { instd::cout<<"a Tager is a carnivore."<<Std::endl; - Continue; to } + if(ch = ='P') - { thestd::cout<<"Beethoven is a pianist."<<Std::endl; * Continue; $ }Panax Notoginseng if(ch = ='T') - { thestd::cout<<"a maple is a tree."<<Std::endl; + Continue; A } the if(ch = ='g') + { -std::cout<<"Chess is a game."<<Std::endl; $ Continue; $ } - } - return 0; the}
C + + Primer plus Sixth Edition programming exercise---Chapter 6th branching and logical operators