snack[1].calory=400; snack[2].brand=\ snack[2].weight=4.4; snack[2].calory=500;
for(int i=0;i<3;i++) { cout << \ cout << \ cout << \ }
delete [] snack; return 0; }
//ex.4.10 数组—方法1 #include
using namespace std; const int Size = 3; int success[Size];
cout<<\ cin >> success[0]>>success[1]>>success[2]; cout<<\ cout<<\ cout<<\ double average=(success[0]+success[1]+success[2])/3; cout<<\ return 0; }
//ex.4.10 array—方法2 #include
using namespace std; array
cout<<\ cin >> ad[0]>>ad[1]>>ad[2];
cout<<\
cout<<\ cout<<\ ad[3]=(ad[0]+ad[1]+ad[2])/3; cout<<\ return 0; }
第五章 循环和关系表达式
//ex.5.1
#include
int main() {
using namespace std;
cout<<\ int num1,num2; cin>>num1>>num2; int sum=0;
for(int temp=num1;temp<=num2;++temp)//or temp++ sum+=temp;
cout<<\ return 0; }
//ex.5.2
#include
int main() {
using namespace std; }
array
ad[i]=i*ad[i-1];
cout<
return 0;
//ex.5.3
#include
using namespace std;
cout<<\ int sum=0,num;
while((cin>>num)&&num!=0) {
sum+=num;
cout<<\ cout<<\ }
return 0; }
//ex.5.4
#include
using namespace std; double sum1,sum2; sum1=sum2=0.0; int year=0; while(sum2<=sum1) {
++year; sum1+=10;
sum2=(100+sum2)*0.05+sum2; }
cout<<\经过\年后,Cleo的投资价值才能超过Daphne的投资价值。\ cout<<\此时,Cleo的投资价值为\,而Daphne的投资价值为\ return 0; }
//ex.5.5
#include
ember\int main() {
using namespace std; int sales[MONTHS],sum=0; for(int i=0;i cout<<\请输入在\的C++ For Fools的销售量:\ cin>>sales[i]; sum+=sales[i]; } cout<<\这一年中的C++ For Fools的总销售量为:\ return 0; } char* months[MONTHS]={\ //ex.5.6 #include ember\ const char* years[3]={\第一年\第二年\第三年\int main() { using namespace std; int year_sale[3],sum=0,sales[3][MONTHS]; for(int i=0;i<3;i++) { int temp=0; cout< cout<<\请输入\的销售量:\ cin>>sales[i][j]; temp+=sales[i][j]; } year_sale[i]=temp; char* months[MONTHS]={\