| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1085 人关注过本帖
标题:谁会做这些题目
只看楼主 加入收藏
zzc11zzc11
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2008-6-18
收藏
 问题点数:0 回复次数:4 
谁会做这些题目
一、填充题

1. 编译器把高级语言程序翻译为                              
2.                   程序直接执行高级语言程序,而不用把程序编译成机器语言。
3. C++程序通常要进过6个开发阶段:编辑、预处理、            、链接、加载和执行。
4.               表示标准输出流。
5.               表示标准输入流。
6. 单行注释以                   开头。
7.               是C++程序中执行的第一个函数。
8. 在C++程序中,所有变量在使用前都要进行                    
9.                语句允许一个程序作出判断。
10. 在if条件中可以使用              运算符和                运算符。
11. 大多数函数都有一个            列表,它们提供了函数间通信的手段。
12. 要指定一个函数不需要返回任何值,应该使用关键字            
13. 要使用函数sqrt,必须包含头文件               
14. 所有的字符串都以              字符结束。
15.               既可以是整数,也可以是整数表达式,它标识某个特定的数组元素。
16. 指针是包含其他变量的              的变量。
17.               使得程序员能够对具有属性、行为和操作的对象进行建模。
18. 类的定义部分由              限定。
19. private成员函数只对该类的              是可见的。
20. 类的实现细节对于用户应该是           的。
21. 当一个成员函数定义在类的定义的外部时,函数名之前要加上              名称和               运算符。
22. 类的              通常定义为private类型,而类的              通常定义为public类型。
23. 数据成员可以在           中初始化,或者可以实例化对象实例之后再设置它们的值。
24. 构造函数不可以           一个值。
25. 继承促进了软件的           
26. 派生类不能访问基类的                  成员;如果允许这种访问,就会违反基类的               
27. 派生类的构造函数总是首先调用它的               的构造函数。
28. 析构函数与构造函数的调用顺序           。因此,派生类的析构函数总是在其基类析构函数            调用。
29. 继承的三种形式是                                      
30.               是通过虚函数实现的。通过声明一个或多个虚函数为              ,可以将类声明为抽象类。

二、程序输出
1.
#include <iostream>
using namespace std;
int main()
{
   int x;
   int y;
   x=34;
   y=4;
   cout<<x*y+9/3<<endl;
   return 0;
}

2.
#include <iostream>
using namespace std;
int main()
{
   int input;
   cout<<"Please enter an integer: ";
   cin>>input;
   if (input!=9)
      cout<<"Hello"<<endl;
   if (input==9)
      cout<<"Goodbye"<<endl;
   return 0;
}

3.
#include <iostream>
using namespace std;
int main()
{
   int input;
   cout<<"Please enter an integer: ";
   cin>>input;
   if (input>=10)
      cout<<"Hello"<<endl;
   cout<<"Goodbye"<<endl;
   return 0;
}

4.
#include <iostream>
using namespace std;
int main()
{
   int x=3;
   int y=9;
   int z=77;
   if (x==(y/3))
      cout<<"H";
   if (z!=77)
      cout<<"q";
   if (z==77)
      cout<<"e";
   if (z*y+x<0)
      cout<<"g";
   if (y==(x*x))
      cout<<"LL";
   cout<<"o!"<<endl;
   return 0;
}

5.
int x=1;
while (x<=5)
{
   x++;
   cout<<"The value of x is: "<<x<<endl;
}
cout<<"The final value of x is: "<<x<<endl;

6.
for (int i=0;i<5;i++)
   cout<<i<<" ";

7.
int grade1=75;
int grade2=45;
cout<<"The student with a grade of "<<grade1<<" "
      <<(grade1>=60?"Passed\n":"Failed\n");
cout<<"The student with a grade of "<<grade2<<" "
      <<(grade2>=60?"Passed\n":"Failed\n");

8.
for (int i=1;i<10;i++)
{
   switch(i)
   {
      case 1:
         cout<<"The value of x is 1\n";
         break;
      case 4:
         cout<<"The value of x is 4\n";
      case 6:
         cout<<"The value of x is 6\n";
         break;
      default:
         cout<<"The value of x is neither 1,4 nor 6\n";
   }
}

9.
int x;
for (x=1;x<10;x++)
{
   if (x==7)
      break;
   if (x==3)
      continue;
   cout<<x<<" ";
}
cout<<endl<<"The final value of x is: "<<x<<endl;

10.
在调用函数f1时,以下程序段的输出结果是什么?
void f1()
{
   int x=5;
   f2(x);
   cout<<x<<endl;
}
void f2(int x)
{
   x+=5;
   cout<<x<<endl;
}

11.
如果下面的程序定义了mystery,那么
cout<<mystery(6,2,5)<<endl;
的输出是什么?
int mystery(int x,int y,int z)
{
   int value=x;
   if (y>value)
      value=y;
   if (z>value)
      value=z;
   return value;
}

12.
如果调用函数f3两次。以下程序段的输出结果是什么?
void f3()
{
   static int x=0;
   x++;
   cout<<x<<endl;
}

13.
以下程序的输出结果是什么?
#include <iostream>
using namespace std;
void f1();
int main()
{
   int x=0;
   cout<<"Initially, x="<<x<<endl;
   f1();
   cout<<"At the end, x="<<x<<endl;
   return 0;
}
void f1()
{
   int x=13;
   cout<<"During call to f1, x="<<x<<endl;
}

14.
以下代码段的输出是什么?
char string1[]="How are you?";
cout<<"string1 is: "<<string1<<endl;
for (int i=0;string1[i] != '\0';i++)
   cout<<string1[i]<<" ";

15.
下面代码的输出是什么?
int number=119;
int *ptr=&number;  //变量number的内存地址是0012ff7c
cout<<number<<" "<<*ptr<<" "<<ptr;

16.
下面代码的输出是什么?
char c[]="Hello you";
char *sPtr=c;
for ( ;*sPtr !='u';sPtr++)
   cout<<*sPtr;

17.
下面代码的输出是什么?
char *sPtr="Boston, MA";
cout<<strlen(sPtr);

18.
下面代码的输出是什么?
Time t1();
t1.setTime(15,22,9);
cout<<"The time is: ";
t1.printStandard();

class Time {
public:
   Time();
   void setTime(int,int,int);
   void printUniversal();
   void printStandard();
private:
   int hour;
   int minute;
   int second;
};
Time::Time()
{
   hour=minute=second=0;
}
void Time::setTime(int h,int m,int s)
{
   hour=(h>=0 && h<24)?h:0;
   minute=(m>=0 && m<60)?m:0;
   second=(s>=0 && s<60)?s:0;
}

19.
以下程序的输出是什么?
#include <iostream>
using namespace std;
class M {
public:
   M(int);
   int mystery(int);
private:
   int data;
   double number;
};
M::M(int q)
{
   data=q;
   number=.5;
}
int M::mystery(int q)
{
   data+=q;
   return data*number;
}
int main()
{
   M stuff(44);
   cout<<stuff.mystery(778);
   return 0;
}

20.
有如下Increment类:
class Increment {
public:
   Increment(int c=0,int i=1);
   void addIncrement() { count+=increment; }
   void print() const;
private:
   int count;
   const int increment;
};
Increment::Increment(int c,int i)
   : increment(i)
{
   count=c;
}
void Increment::print() const
{
   cout<<"count="<<count<<", increment="<<increment<<endl;
}
下面代码的输出是什么?
Increment object(65,7);
cout<<"Before incrementing: ";
object.print();
for (int j=0;j<6;j++) {
   object.addIncrement();
   cout<<"After increment "<<j+1<<": ";
   oblect.print();
}

三、代码改错
1.
#include <iostream>;
using namespace std;
int main()
{
   int x=30;
   int y=2;
   cout <<x*y+9/3<<endl;
   return 0;
}

2.
int 1stPlace = 6
1stPalce=6;

3.
测试q是否等于0
int q=0;
cout<<"q is: "<<q;
if (q = 0)
cout<<"q is equal to 0";

4.
比较两个整数是否相等
int x=9;
int y=3;
if (x =! y)
cout<<"Not equal";

5.
if (grade>=60)
   cout<<"Passed.\n"
else
   cout<<"Failed.\n"
   cout<<"You must take this course again.\n"
6.
以下程序计算1到5之间的所有整数的乘积(包括1和5)
for (int i=1;i<5;i++) {
   int product = 1;
   product *= i;
}

7.
以下程序段打印0到100之间的所有偶数(包括0和100)
for (int x=0;x%2!=1;x+=2) {
   cout<<x<<" ";
   if (x>=100)
      break;
}

8.
下面的程序段定义了函数maximum,该函数返回3个整数中的最大值
int maximun(int x,int y,int z);
{
   int max=x;
   if (y>max)
      max=y;
   if (z>max)
      max=z;
   return max;
}

9.
下面的程序创建一个枚举类型Status,并声明一个Status类型的变量myStatus
enum Status = { CONTINUE; WON; LOST };
Status myStatus = 1;

10.
下面的程序段应该定义两个函数
void f2()
{
   cout<<"During call to f2.\n";

   void f3()
   {
      cout<<"During call to f3.\n";
   }

}

11.
下面的代码应该将8赋给array的第105个元素
array(105) = (8);

12.
下面的for循环应该将所有的数组元素初始化为-1
int array[10];
for (int 1=0;i<9;i++)
   array[i]=-1;

13.
下面的代码段应该声明两个数组,分别包含5个元素和6个元素
const int arraySize=5;
int a[arraySize];
arraySize=6;
int b[arraySize];

14.
以下代码段应该通过指针打印a和a的内容
int a = 7;
int *aptr = &a;
cout<<*a<<aptr

15.
以下代码应该用指针运算来打印数组元素
int a[5]={1,2,3,4,5};
int *aptr=&a[0];
for (int i=0;i<=5;i++)
   cout<<*(aptr+i);

16.
下面代码定义Q类
class Q {
public:
   int Q(int);
   void setQ(int);
   void printQ();
   int operateQ(int);
private:
   int qData;
};

17.
下面代码定义Q类的setQ成员函数。该定义位于Q类定义的外部
void setQ(int input)
{
   qData=input;
}

18.
下面代码定义Time类
class Time {
public:
   Time(int = 0, int = 0, int = 0);
   void setTime(int,int,int);
   void printUniversal();
   void printStandard();
private:
   int hour;
   int minute;
   int second;
}

19.
   int main()
   {
      int x;
      int y;
      int z;
      cout << "Enter two integer values: ";
      cin << x, y;
      if ( x > y )
         z == x - y;
      if ( x < y )
         z == y - x
      if ( x == y );
         z == x + y;
      cout << "The value of z is: " << z;
   }

20.
   #include <iostream>
   #include <iomanip>
   using namespace std;
   int main()
   {
      int i = 1;
      double a;
      double b;
      cout << setprecision( 2 );
      for ( int i; i <= 2; i++ )
         cout << "i is now equal to " << i << endl;
         for ( int j; j <= 3; j++ ) {
            cout << "\tj is now equal to " << j << endl;
            cout << "\t\ti + j = " << i + j << "\ti - j = "
                 << i - j << endl;
            cout << "\t\ti * j = " << i * j << "\ti ^ j = "
                 << pow( i, j ) << endl;
            if ( j = 0 )
               continue;
            else {
               a = i;
               b = j;
               cout << "\t\ti / j = " << a / b
                       "\ti % j = " << a % b << endl;
            }
         }
      cout << "\nThe final values of i and j are: " << i
           << " and " << j << endl;
      return 0;
   }

21.
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
enum Months { JAN = 1, FEB, MAR, APR, MAY, JUN,
                         JUL, AUG, SEP, OCT, NOV, DEC };
void generateDate( int &, int &, int );
void printDate( Months, int, int );
int validDate( int, int );
int main()
{
   int month = 1;
   int day = 1;
   int year = 1900;
   srand( time( 0 ) );
   printDate( month, day, year );
   year = getYear( year );
   getMonth();
   day = getDay();
   if ( validDate( month, day, year ) == true )
      printDate( month, day, year );
   return 0;
}

int getMonth()
{
   Month myMonth = rand() % 12 + 1;
   return myMonth;
}

int getYear( int aYear )
{
   return rand() % 101 + 1900;
}

void getDay()
{
   return rand() % 31 + 1;
}

void printDate( Months month, int day, year );
{
   switch ( month ) {
      case JAN:
         cout << "January " << day << ", " << year << endl;
      case FEB:
         cout << "February " << day << ", " << year << endl;
         break;
      case MAR:
         cout << "March " << day << ", " << year << endl;
         break;
      case APR:
         cout << "April " << day << ", " << year << endl;
         break;
      case MAY:
         cout << "May " << day << ", " << year << endl;
         break;
      case JUN:
         cout << "June " << day << ", " << year << endl;
         break;
      case JUL:
         cout << "July " << day << ", " << year << endl;
         break;
      case AUG:
         cout << "August " << day << ", " << year << endl;
         break;
      case SEP:
         cout << "September " << day << ", " << year << endl;
         break;
      case OCT:
         cout << "October " << day << ", " << year << endl;
         break;
      case NOV:
         cout << "November " << day << ", " << year << endl;
         break;
      case DEC:
         cout << "December " << day << ", " << year << endl;
         break;
      default:
         cout << "invalid month\n";
   }
}

bool validDate( int month, int day, int year )
{
   int month;
   int day;
   int year;
   if ( year < 1900 || year > 2001 )
      return false;
   else if ( month < 1 || month > 12 )
      return false;
   else if ( day < 1 || day > 31 )
      return false;
   else if ( day == 31 && month == APR || month == JUN
             || month == SEP || month == NOV )
      return false;
   else if ( month == 2 && day > 28 )
      return false;
}

22.
#include <iostream>
#include <iomanip>
#include <ctime>
using namespace std;
const int NUM_GRADES = 10;
const int NUM_SUDENTS = 3;
int findHighest( int );
int findLowest( int * );
void printDatabase( const int [][], const char [][ 20 ] );
int main()
{
   int student1[ NUM_GRADES ] = { 0 };
   int student2[ NUM_GRADES ] = { 76, 89, 81, 42, 66, 93, 104,
                                 91, 71, 85, 105 };
   int student3[ NUM_GRADES ] = { 65, 69, 91, 89, 82, 93, 72,
                                 76, 79, 99 };
   char names[ NUM_SUDENTS ][ 20 ] = { "Bob", "John", "Joe" };
   int database[ NUM_SUDENTS ][ NUM_GRADES ];
   int i = 0;
   srand( time( 0 ) );
   for ( i = 0; i < NUM_GRADES; i++ )
      student1[ NUM_GRADES ] = rand() % 50 + 50;
   for ( i = 1; i < NUM_GRADES; i++ ) {
      database[ 0 ][ i ] = student1[ i ];
      database[ 1 ][ i ] = student2[ i ];
      database[ 2 ][ i ] = student3[ i ];
   }
   printDatabase( database, studentNames );
   for ( i = 0; i < NUM_SUDENTS; i++ ) {
      cout << studentNames[ i ] << "'s highest grade is: "
           << findHighest( student1 ) << endl
           << studentNames[ i ] << "'s lowest grade is: "
           << findLowest( database[ i ] ) << endl;
   }
   return 0;
}

int findHighest( int )
{
   int highest = a[ 0 ];
   for ( int i = 1; i <= NUM_GRADES; i++ )
      if ( a[ i ] > highest )
         highest = a[ i ];
   return highest;
}

int findLowest( int a[] )
{
   int lowest = a[ 0 ];
   for ( int i = 1; i < NUM_GRADES; i++ )
      if ( a[ i ] < lowest )
         lowest = a[ i ];
   return lowest;
}

void printDatabase( int a[][ NUM_GRADES ], char names[][ 20 ] )
{
   cout << "Here is the grade database\n\n"
        << setw( 10 ) << "Name";
   for ( int n = 1; n <= NUM_GRADES; n++ )
      cout << setw( 4 ) << n;
   cout << endl;
   for ( int i = 0; i < NUM_SUDENTS; i++ ) {
      cout << setw( 10 ) << names[ i ];
      for ( int j = 0; j < NUM_GRADES; j++ )
         cout << setw( 4 ) << a[ i, j ];
      cout << endl;
   }
   cout << endl;
}

四、编程题

1. 输入/输出数据,进行简单的运算处理

2. 最大、最小值处理,数据之间的关系判断等函数编写

3. 类的定义和运用

搜索更多相关主题的帖子: 编译器 开发 
2008-06-18 15:16
lyd253261362
Rank: 1
等 级:新手上路
帖 子:91
专家分:2
注 册:2007-4-26
收藏
得分:0 
参考参考

1.一般情况是:编译器把高级语言程序翻译为汇编代码。
2.
3.编译
4.cout
5.cin
6.//
7.winmain()
8.初始化。
9.if
10.条件运算符和逻辑运算符
11.
12.void
13.#include<math.h>
14.'\0'
15.数组首个元素。
16.地址
17.面向对象
18.
19.friend==友元
20.
21.类的名称和分隔运算符
22.变量,成员函数
23.构造函数中初始化
24.
25.可重用性。
26.私有,封装性。
27.基类,
28.相反,前
29.公有(public)、保护(protected)、私有(private)
30.多态性是通过虚函数实现。通过声明一个或者多个虚函数为纯虚函数,可以将类声明为抽象类。
2008-06-18 21:23
lyd253261362
Rank: 1
等 级:新手上路
帖 子:91
专家分:2
注 册:2007-4-26
收藏
得分:0 
二、
二、
1.139
2.Please enter an integer:4
  Hello
  press any key to continue
  Please enter an integer:4
  Goodbye
  press any key to continue
3.Please enter an integer:6
  Goodbye
  press any key to continue
  lease enter an integer:10
  Hello
  press any key to continue
2008-06-18 21:34
lyd253261362
Rank: 1
等 级:新手上路
帖 子:91
专家分:2
注 册:2007-4-26
收藏
得分:0 
订正:
19.
   int main()
   {
      int x;
      int y;
      int z;
      cout << "Enter two integer values: ";
      cin>>x;
      cin>>y;
      if ( x > y )
         z = x - y;
      if ( x < y )
         z = y - x;
      if ( x == y );
         z = x + y;
      cout << "The value of z is: " << z<<endl;
      return 0;
   }
2008-06-18 21:45
yunzhongfan
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2008-9-15
收藏
得分:0 
kankan
2008-09-15 21:00
快速回复:谁会做这些题目
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.032527 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved