赞
踩
如果可以,还请点个赞
解: 1全面兼容c 2面向对象的方法
Program,-page,_lock,test2,3inl,@mail,A_B_C_D
解:第1、3、4、7个
解:
#include //指示编译器将文件iostream.h中的代码
//嵌入到该程序中该指令所在的地方
void main() //主函数名,void 表示函数没有返回值
{ //函数体标志
cout<<“Hello!\n”; //输出字符串Hello!到标准输出设备(显示器)上。
cout<<“Welcome to C++!\n”; //输出字符串Welcome to c++!
}
解:const float PI = 3.1416f;
float a = PI;
解:enum Color{WHITE,BLACK = 100,RED,BLUE,GREEN = 300};
BLUE = 102
枚举类型是依次加一的
解:解释说明用。 在C++中,有两种给出注释的方法:一种是延用C语言方法,使用"/“和”/“括起注释文字。另一种方法是使用”//“,从”//"开始,直到它所在行的行尾,所有字符都被作为注释处理。
解:由运算符、运算量和变量组成的式子。x = 5+7是表达式,它的值是12
解:(1)201/4 = 50 //取整
(2)201%4 = 1 //取余
(3)201%4.0 = 50
解:a = 30;
b = a++;
c= ++a;
a = 32,b = 30,c = 32
解:
int a[26];
for(int i = 0;i<26;i++){
cin>>a[i];
}
int n;
for(n = 0;n<100;n++){}
解:100
解:#include
using namespace std;
int main(){
for(int n = 100;n<200;n++2){
cout<<n<<endl;
}
return 0;
}
解:if(x = 3)这条语句非零,永远正确,永远往下执行
if(x == 3)判断x是否等于3
解:#include
using namespace std;
int main(){
int x,y;
cout<<“请输入第一个数”<<endl;
cin>>x;
cout<<“请输入第二个数”<<endl;
cin>>y;
if(x > y){
x = y;
}
else if(x < y){
y = x;
}
else{
x = x;
y = y;
}
cout<<x<<" "<<endl;
return 0;
}
解:
#include
using namespace std;
int main(){
int i;
int j;
i = 10;
j = 20;
cout<<"i+j = <<i+j; //这句原样输出应为一对双引号“ ”,输出后的值为30
return 0;
}
解:#include
using namespace std;
int main(){
int a;
cout<<“请输入一个数字”<<endl;
cin>>a;
cout<<a;
return 0;
}
解:
#include <iostream.h>
int main()
{
cout << “The size of an int is:\t\t” << sizeof(int) << " bytes.\n";
cout << “The size of a short int is:\t” << sizeof(short) << " bytes.\n";
cout << “The size of a long int is:\t” << sizeof(long) << " bytes.\n";
cout << “The size of a char is:\t\t” << sizeof(char) << " bytes.\n";
cout << “The size of a float is:\t\t” << sizeof(float) << " bytes.\n";
cout << “The size of a double is:\t” << sizeof(double) << " bytes.\n";
return 0;
}
程序运行输出:
The size of an int is:4 bytes.
The size of an short is:2 bytes.
The size of an long int is:4 bytes.
The size of an char is:1 bytes.
The size of an float is:4 bytes.
The size of an double is:8 bytes.
解:
#include
using namespace std;
int main(){
for(int i = 32;i<127;i++){
cout<<(char)i<<" "<<endl;
return 0;
}
解:
#include
using namespaec std;
int main(){
unsigned int x;
unsigned int y = 100;
unsigned int z = 50;
x = y-z;
cout<<"Difference is : “<<x<<endl;
x = z-y;
cout<<”\nNow difference is : "<<x<<endl;
return 0;
}
解:
#include
int main()
{
int myAge = 39; // initialize two integers
int yourAge = 39;
cout << “I am: " << myAge << " years old.\n”;
cout << “You are: " << yourAge << " years old\n”;
myAge++; // postfix increment
++yourAge; // prefix increment
cout << “One year passes…\n”;
cout << “I am: " << myAge << " years old.\n”;
cout << “You are: " << yourAge << " years old\n”;
cout << “Another year passes\n”;
cout << “I am: " << myAge++ << " years old.\n”;
cout << “Let’s print it again.\n”;
cout << “I am: " << myAge << " years old.\n”;
cout << “You are: " << yourAge << " years old\n”;
return 0;
}
程序运行输出:
I am 39 years old
You are 39 years old
One year passes
I am 40 years old
You are 40 years old
Another year passes
I am 40 years old
You are 41 years old
Let’s print it again
I am 41 years old
You are 41 years old
解:
不同常量的值不可以修改,所以常量在定义的时候必须初始化,任何尝试修改常量的操作都会导致编译出错。
变量可以通过赋值来改变值,变量可以在定义时不进行初始化。
解:
auto(自动)
extern(外部)
static(静态)
register(寄存器)
解:
1.2<3&&6<9
2.!(4<7)
3.!(3>5)||(6<2)
1.true 2.false 3.true
解:
1.a|b-c
2.a^b&-c
3.a&b|c
4.a|b&c
1.-1 2.1 3.3 4.3
解:
1.!a|a //1
2.~ a | a //-1
3. a ^ a //0
4. a >> 2 //0
解:
#include
using namespace std;
int main() {
char n;
do {
cout << “现在正在下雨吗” << endl;
cout << “请输入Y或N” << endl;
cin >> n;
} while ( n != ‘Y’ && ‘N’);
if (n == ‘Y’)
cout << “现在正在下雨” << endl;
if (n == ‘N’)
cout << “现在没有下雨” << endl;
return 0;
}
等级:优 90小于等于分数小于等于100
良 80小于等于分数小于90
中 60小于等于分数小于80
差 0小于等于分数小于60
解:
#include
using namespace std;
void main()
{
cout<<“你考试考了多少分”(0-100):”<<endl;
int i;
cin>>i;
if(i<=100&&i>=90)cout<<“\n优”;
if(i<=90&&i>=80)cout<<“\n良”;
if(i<=80&&i>=60)cout<<“\n中”;
if(i<=60&&i>=0)cout<<“\n差”;
}
解:
#include
using namespace std;
int main()
{
char n;
cout<<"Menu: A(dd) D(elete) S(ort) Q(uit),Select one: "<<endl;
cin>>n;
while(n!=‘Q’)
{
switch(n)
{
case ‘A’:
{
cout<<“数据已经增加”<<endl;break;
}
case ‘D’:
{
cout<<“数据已经删除”<<endl;break;
}
case ‘S’:
{
cout<<“数据已经排序”<<endl;break;
}
}
cin>>n;
}
return 0;
}
解:
1.用while:
include<iostream.h>
void main()
{int i,j,n,m;
i=2;
while(i<101)
{m=1;n=i/2;j=2;
while(j<=n)
{ if(i%j==0)
{m=0;
breake;
}
j++;
}
if(m)
cout<<i<<“”;
i++;
}
}
2.用do…while
#include<iostream.h>
void main()
{int i,j,n,m;
i=2;
do
{m=1;n=i/2;j=2;
do
{if(i%j==0)
{m=0;
breake;
}
j++;
}while(j<=n);
if(m)
cout<<i<<“”;
i++;
}while(i<101);
}
3.用for
void main()
{int i,j,n,m;
for(i=2;i<101;i++)
{m=1;
n=i/2;
for(j=2;j<=k;j++)
{if(i%j==0)
{m=0;
breake;
}
}
if(m)
cout<<i<<“”;
}}
#include
using namespace std;
int main(){
for(int i = 0;i<10;i++){
if(i%2==0){
continue;
}
else{
break;
}
}
return 0;
}
解:
while:
#include <iostream>
using namespace std;
int main() {
int a = 99;
int b;
cout << "请猜一个1-100的数" << endl;
cin >> b;
while (b!=a)
{
cout << "猜错了,再猜" << endl;
cin >> b;
}
cout << "恭喜你,回答正确" << endl;
return 0;
}
do……while
#include <iostream>
using namespace std;
int main() {
int a = 99;
int b;
cout << "请猜一个1-100的数" << endl;
cin >> b;
do{
cout << "猜错了,再猜" << endl;
cin >> b;
} while (b != a);
cout << "恭喜你,回答正确" << endl;
return 0;
}
解:
不能对枚举类型的变量赋值,但是枚举类型的值可以赋给整型变量
解:
#include <stdio.h> void main() { enum color {red,yellow,blue,white,black}; enum color i, j, k, pri; int n = 0, loop; for(i=red;i<=black;i++) for(j=red;j<=black;j++) if (i != j) { for (k = red; k <= black; k++) { if ((k != i) && (k != j)) { n = n + 1; printf("%-4d", n); for (loop = 1; loop <= 3; loop++) { switch (loop) { case 1:pri = i; break; case 2:pri = j; break; case 3:pri = k; break; default:break; } switch (pri) { case red:printf("%-10s", "red"); break; case yellow:printf("%-10s", "yellow"); break; case blue:printf("%-10s", "blue"); break; case white:printf("%-10s", "white"); break; case black:printf("%-10s", "black"); break; default:break; } } printf("\n"); } } } printf("\ntotal:%5d\n", n); }
解:
#include <iostream>
using namespace std;
int main() {
for (int i = 0; i <= 9; i++)
{
for (int j = 1; j <= i; j++)
{
cout << j << "*" << i << "=" << i * j << " ";
}
cout << endl;
}
return 0;
}
解:
它们在计算机内是用补码表示的,最高一位是符号位,0表示正,1表示负。
无符号的整数没有符号位。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。