摘要: #include<iostream>usingnamespace std;int main(){ char c1,c2,c3,c4; cout<<"Enter your first,middle and last initials"<<endl;//注意提醒用户输入的信息。 cin>>c1>>c2>>c3;//从键盘读取字符。 cout<<"You entered"<<c1<<c2<<c3<<endl; cout<&l 阅读全文
posted @ 2012-06-22 18:14 蚂蚁踩死了大象 阅读(131) 评论(0) 推荐(0)
摘要: #include<iostream>#include<fstream>usingnamespace std;int main(){ double x; int i,j; ifstream infile1("A.txt"); ifstream infile2("B.txt");//声明从什么文件中读取数据。 infile>>i; infile>>j>>x;//注意:读取、读入文件信息使用的符号不一样。 infile.close(); cout<<"From first fil 阅读全文
posted @ 2012-06-22 17:57 蚂蚁踩死了大象 阅读(118) 评论(0) 推荐(0)
摘要: #include<iostream>#include<fstream>//使用用于文件输入和输出的fstream头文件。usingnamespace std;int main(){ double income=123.45,expenses=987.65; int week=7,year=2006; ofstream outfile("A.txt");//写入文件。 outfile<<"Week="<<week<<endl;<<"Year=" <<ye 阅读全文
posted @ 2012-06-22 17:32 蚂蚁踩死了大象 阅读(182) 评论(0) 推荐(0)
摘要: /*从键盘读取数据 1.使用cin对象从键盘输入数据 2.提示输入*/#include<iostream>#include<iomanip>usingnamespace std;int main(){ double income,expense; int month; cout<<"What month is it?"<<endl; cin>>month; cout<<"You have entered the month="<<month<<endl; co 阅读全文
posted @ 2012-06-22 10:49 蚂蚁踩死了大象 阅读(197) 评论(0) 推荐(0)
摘要: #include<iostream>#include<cmath>//包括数学函数的头文件。#include<iomanip>usingnamespace std;int main(){ double x=3.0,y=4.0; double a,b,c,d,e,f; float g; a=sin(x); b=exp(x); c=log(x); d=sqrt(x); e=pow(x,y); f=sin(y)+exp(x)-log10(y)*sqrt(y)/pow(3.2,4.4); g=log(x);//注意,c和g值相同,但是类型不同... 阅读全文
posted @ 2012-06-22 10:20 蚂蚁踩死了大象 阅读(176) 评论(0) 推荐(0)
摘要: /*主要内容: 1.算术运算的优先级 2.算术声明的缺陷 3.在算术表达式中混合整数和实数 4.类型强制转换 5.边缘效应*/#include<iostream>usingnamespace std;int main(){ int i=1,j=1, k1=10,k2=20,k3=30,k4=40,k5=50, k,h,m,n; double a=7,b=6,c=5,d=4, e,p,q,x,y,z; cout<<"*********Section 1*********... 阅读全文
posted @ 2012-06-21 17:54 蚂蚁踩死了大象 阅读(148) 评论(0) 推荐(0)
摘要: #include<iostream>usingnamespace std;int main(){ int i,j,k,p,m,n; double a,b,c,d,e,f,g,h,x,y,z; i=5; j=5; k=11; p=3; x=3.0; y=4.0; cout<<"---------Section 1 output" "-------"<<endl<<endl; a=x+y; b=x-y; c=x*y; d=x/y; e=d+3.0; f=d+3; i=i+1; j=j... 阅读全文
posted @ 2012-06-21 16:11 蚂蚁踩死了大象 阅读(91) 评论(0) 推荐(0)
摘要: #include<iostream>usingnamespace std;int main(){ char c1,c2,c3,c4,c5,c6; int i,j; c1='g'; c2='<'; c3='\n';//转义序列("newline")\n被c++看作单个字符,输出时,不显示任何字符,光标只是跳至新的行。 c4='7';//结果为7 c5=63; c6=c1-3; i=c4;//结果为55 j=c4+2;//结果为57 cout<<"c1="<& 阅读全文
posted @ 2012-06-21 16:09 蚂蚁踩死了大象 阅读(93) 评论(0) 推荐(0)
摘要: //创建常量以及更多显示变量值的信息。#include<iostream>#include<iomanip>usingnamespace std;int main(){ constdouble PI=3.1415926; cout<<"1.PI=[["<<PI<<"]]"<<endl; cout<<"2.PI=[["<<setw(15)<<PI<<"]]"<<endl;//域宽为15空 阅读全文
posted @ 2012-06-21 16:06 蚂蚁踩死了大象 阅读(122) 评论(0) 推荐(0)
摘要: #include<iostream>usingnamespace std;int main(){ int tank_id;//使用关键字int将变量(tank_id)声明为整型 double diameter,pressure;//使用关键字double将变量(diameter和pressure)声明为实数 tank_id=12; diameter=111.1; pressure=100;//赋值语句使用=符号将数值存储在被声明的变量的内存单元中 cout<<"Tank_id="<<tank_id<<",Diamet 阅读全文
posted @ 2012-06-21 15:58 蚂蚁踩死了大象 阅读(132) 评论(0) 推荐(0)