C++ Primer Plus 第六章

1.if else if else

2.逻辑运算符 ||或 &&与 !非

3.||、&&是一个顺序点,先左后右,优先级比关系运算符低(大于小于)

4.!优先级比较高

5.cctype头文件,下有很多处理字符的函数,P179页

6.3元运算符 x = (x>y)?x:y

7.switch(integer-expression)
{
case label1:statement
case label2:statement
case label3:statement
...
default:statement
}
lbael经常使用枚举量来表示

8.使用break语句,使程序跳到switch或循环后面的语句处执行;continue让程序跳过循环体中余下的代码

9.写入文本文件 包含头文件fstream,有类ofstream,
声明对象 ofstream outFile;
关联文件 outFile.open("文件名");
使用方法:outFile<<文本  outFile.set(ios_base::showpoint) outFile.precision(2)
关闭文件 outFile.close()

10.读取文本文档 包含头文件fstream,有类ifstream,
声明对象 ifstream inFile;
关联文件 inFile.open("文件名");
使用方法:inFile>>文本  outFile.getline(char*,int),inFile.get(char),inFile.get(),类似于cin
inFile.eof(),判断是否文件尾 inFile.fail()判断文件读取是否类型不匹配错误,错返回true
当inFile作为逻辑判断时,自动转化为inFile.good()
关闭文件 inFile.close()

6.10 复习题

6.11 练习题
1.
#include <iostream>
#include <string>
#include <array>
#include <cctype>
using namespace std;

const int ArSize = 16;
int main()
{
 cout<<"Pleaser Enter zifucuan,meet number clear away,big char deversion small char!,input @ stop\n";
 char ch;
 while(cin.get(ch) && ch != '@')
 {
  if(isalpha(ch)) cout<<(char)tolower(ch);
 }
 while(1);//让dos页面不关闭
 return 0;
}

2.
#include <iostream>
#include <string>
#include <array>
#include <cctype>
using namespace std;

const int ArSize = 16;
int main()
{
 array<double,10> ar = {0.0};
 cout<<"Enter max 10 double \n";
 int i;
 for(i = 0 ;i<10;i++)
 {
  cin>>ar[i];
  if(!cin)
  {
   cin.clear();
   while(cin.get() != '\n');
   if(i == 0)
   {
    i--;
    cout<<"请输入double 值\n";
    continue;
   }
   break;
  }
 }
 double sum = 0.0;
 for(int j = 0;j<i;j++)
 {
  cout<<ar[j]<<endl;
  sum = sum + ar[j];
 }
 double average = sum / i;
 cout<<"平均值为:"<<average<<endl;
 int t = 0;
 for(int j = 0;j<i;j++)
 {
  if(ar[j] > average) t++;
 }
 cout<<"有"<<t<<"个值高于平均值!\n";
 while(1);//让dos页面不关闭
 return 0;
}

 3-9 没时间做

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值