第14周-输入输出流,文本文件-项目0-课后实践·程序阅读2

来源:互联网 发布:artemplate.js 编辑:程序博客网 时间:2024/06/08 02:07

/* * Copyright (c) 2014, 烟台大学计算机学院 * All rights reserved. * 文件名称:test.cpp * 作    者:刘畅* 完成日期:2015 年 6  月  4 日 * 版 本 号:v1.0 * * 问题描述:阅读程序。* 输入描述:;* 程序输出::

(1)

#include <iostream>using namespace std;int main( ){    char *a="BASIC";//字符指针指向'B'    for(int i=4; i>=0; i--)        cout.put(*(a+i));   //从最后一个字符开始输出    cout.put('\n');    return 0;}

运行结果:



(2)

#include<iostream>#include<cstdio>int main(){    char *a="BASIC";    for(int i=4; i>=0; i--)        putchar(*(a+i));    putchar('\n');    return 0;}

运行结果:


(3)

#include <iostream>using namespace std;int main( ){    float grade;    cout<<"enter grade:";    while(cin>>grade)  //能从cin流读取数据    {        if(grade>=85)            cout<<grade<<" GOOD!"<<endl;        if(grade<60)            cout<<grade<<" fail!"<<endl;        cout<<"enter grade:";    }    cout<<"The end."<<endl;    return 0;}

运行结果:


0 0
原创粉丝点击