C++考试,老师说了题目·叫我们找答案,麻烦各位网友帮忙完成下。小弟谢谢啦

C++
第一章
一.填空题。
1.C++语言的前身是______语言。
2.如果test.cpp是一个源程序文件,则其中的主函数的函数名是_______。
3.cout与操作符_______配合可用于显示输出。
4.cin与操作符________配合可用于键盘输入。
二.程序设计。
1.设计一个程序,显示输出“C++程序设计”。
2.设计一个程序,通过键盘输入任意的两个整数,计算并显示输出这两个整数之和。
 第二章
一.填空题
1.字符串“字符串”占用_______字节的空间。
2.执行char ch1=’D’-1,ch2=70;后,ch1中的字符是_______,ch2的字符是_______。
3.int(-47.45),double(34)和char(71)值用常量表示分别是________、_______和________。
4.执行cout <<55+045;后,屏幕上显示的是_______。
5.执行cout<<’C’+10;后屏幕上显示的是_______。
6.x+y<3 的相反条件可表示为_________。
7.x>3||x<-4的相反条件不用运算符!可表示为_________。
8.执行int x=3,y=6;y = x ;后,x的值是_______,y的值是______。
二.选择题
1.若x是一个bool型变量,则x&&!x的值是_______。
A.true B.false
C.与x的值相同 D.与x的值相反
2.若x是一个bool型变量,则x||!x的值是_______。
A.true B.false
C.与x的值相同 D.与x的值相反
3.A>B&&A<=B的值为________。
A.ture B.false
C.与A>B的值相同 D.与A<=B的值相同
4.A>B||A<=B的值为__________.
A.ture B.false
C.与A>B的值相同 D.与A<=B的值相同
5.执行bool ok=2!=3;cout<<ok;显示在屏幕上的是________。
A.ture B.false
C.1 D.0
6.若x是一个bool型变量,则x&&5的值是________。
A.ture B.false
C.与x的值相同 D.与x的值相反

三.运行程序。
1.
#include<iostream.h>
void main ( )
{ int a1,a2;
int i=5,j=7,k=0;
a1=!k;
a2=i!=j;
cout<<”a1=”<<a1<<”;””<<”a2=”<<a2<<endl;
}
3.
#include<iostream.h>
void main ( )
{ int a,b,c,d,x;
a=c=0;
b=a++,1;
d=20;
d>>=2;
cout<<”a=”<<a<<”;”<<”b=”<<b<<”;”<<”d=”<<d<<endl;
}
第12章
运行程序
1.
#include<iostream.h>
#include<iomanip.h>
void main( )
{
double radius,area;
radius=2.5;
area=3.14159*radius;
cout<<setw(10)<<radius<<setw(10)<<area<<endl;
cout.setf(ios::showpoint);
cout.precision(4);
cout<<setw(10)<<radius<<setw(10)<<area<<endl;
cout.setf(ios::showpoint);
cout.precision(5);
cout<<setw(10)<<radius<<setw(10)<<area<<endl;

3.
#include<iostream.h>
void main ( )
{ iTfstream file(“fname.dat”,ios::ios::nocreate);
int x;
while(file>>x)
cout <<x<<’ ‘;
cout<<endl;
file.close( );
}
二.编程题。
1.设计一个程序,实现把100以内的所有素数保存在一个文本文件中。

第1个回答  2012-06-16
一:C语言 、main 、<<、>>

1.
#include<iostream>
using namespace std;
void main ( )
{
cout<<"C++程序设计"<<endl;
}
2.
#include"stdafx"
#include<iostream>
using namespace std;
void main()
{
int m,n,sum;
cout<<"请输入两个整数:";
cin>>m>>n;
sum=m+n;
cout<<"这两个数的和为:"<<sum<<endl;
}
第二章

1.6
2.C、F
3.-47、34、G
4.92
5.77
6.x+y>=3
7.x<3&&x>-4
8.x=3,y=3

B A B A C C

1.a1=1;a2=1
3.a=1;b=0;d=5
第12章

1.
(一个数占十个字节 右对齐输出)
2.5 7.85398
2.500 7.854
2.5000 7.8540

3.输出的是从文件"fname.dat"里读到的x

#include<iostream>
#include<cmath>
#include<fstream>
using namespace std;
//设计一个程序,实现把100以内的所有素数保存在一个文本文件中
void main ( )
{
ofstream file;
file.open("1.txt",ios_base::out);///自己建一个文件
if(file.fail()==true)
{
cout<<"open fail!";
return ;
}
for(int i=2;i<=100;i++)
{
int s=0;/*统计数i的因子*/
for(int j=1;j<=(int)sqrt(double(i));j++)
{
if(i%j==0)
s++;
}
if(s==1)/*i的因子少于2时*/
file<<i<<" ";
}

}
第2个回答  2012-06-17
一填空题
1. c
2. main
3. <<
4. >>
二程序设计
1.>
#include<iostream>
using namespace std;
int main()
{
cout<<"C++程序设计"<<endl;
return 0;
}
2.>
using namespace std;
int main()
{
int num1,num2;
cout<<"请输入两个整数"<<endl;
cout<<"第一个整数"<<num1<<"第二个整数"<<num2<<"之和为:"<<num1+num2<<endl;
return 0;
}
第二章
一.填空题
1. 1
2. 'C' 'F'
3. -47 34 'G'
4. 92
5. 77
6. x+y>=3
7. x>=-4 && x<=3
8. 3 3
二、选择题
B A B A C C
三、运行程序
1. a1=1;a2=1
3. a=1;b=0;d=5

1.
2.5 7.85398
2.500 7.854
2.5000 7.8540
3.
把fname.dat文件中的所有数据数据输出,直到文件结束停止

二、编程题
#include <iostream>
#include<fstream>
#include<math.h>
using namespace std;

int main()
{
int i,num;
ofstream out( "result.txt");
if ( !out){
cout<< "file error!";
return 1;
}
bool isPrime;
for ( num = 4 ; num <= 100 ; num++){
isPrime = true;
for(i=2;i<=int(sqrt(num));i++){
if(!(num%i)){
isPrime = false;
break;
}
}
if(isPrime)
out<<num<< " ";
}
out.close();
return 0;
}
第3个回答  2012-06-17
1.C++语言的前身是______语言。

看到这个问题,就不想找了。
C++的语言前身是C没错。
但是C++跟C已经基本完全独立两种语言了。
这样很容易加深大部分人的误解,学C++要先学C。本回答被提问者和网友采纳
第4个回答  2012-06-16
一、1.C 2.main 3.std 4.std
二、1.#include<iostream>
using namespace std;
int main()
{
cout<<"C++程序设计"<<endl;
return 0;
}太简单了,实在做不下去了
相似回答