| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 744 人关注过本帖
标题:求助!!3题改错的和10题给出程序写结果的。急。。。。。在线等。麻烦高手了 ...
只看楼主 加入收藏
a188a100
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2008-6-25
收藏
 问题点数:0 回复次数:4 
求助!!3题改错的和10题给出程序写结果的。急。。。。。在线等。麻烦高手了!
6.    找出下面程序中的错误并说明理由。
class base{
    protected:
        int p;};
void fun()
{    
base b;
    int x=b.p;
}


7.    分析下列程序,指出错误的地方并予以改正。
class base{
    public:
        int b;};
class base1:public base{?}
class base2:public base{?}
class derived:public base1:public base2{
    public:
        int f();
};
main()
{
derived d;
d.b();
d.base::b;
}


8.    如果希望下列程序的运行结果如下,请将程序补充完整。
Base¢s cons.
Derived¢s cons.
Derived¢s des.
Base¢s des.
class Base{
public:
    Base(){cout<< “Base&cent;s cons.”<<endl;}
                      {cout<< “Base&cent;s des.”<<endl;}
};
class Derived:public Base{
public:
    Derived(){cout<< “Derived&cent;s cons.”<<endl;}
    ~Derived(){cout<< “Derived&cent;s des.”<<endl;}
};
void main()
{    Base *ptr=                       
    delete ptr;}

1.    写出下列程序的运行结果
#include <iostream.h>
int i=15;
void main()
{
int i;
i=100;
::i=i+1;
cout<<::i<<endl;
}





2.    写出下列程序的运行结果
class Person{
public:
      Person(){cout<< “Constructor of Person”<<endl;}
~Person(){cout<< “Destructor of Person”<<endl;}
};
class Student:public Person{
public:
      Student(){cout<< “Constructor of Student”<<endl;}
      ~Student(){cout<< “Destructor of Student”<<endl;}
};
class Teacher:public Person{
public:
Teacher(){cout<< “Constructor of Teacher”<<endl;}
~Teacher(){cout<< “Destructor of Teacher”<<endl;}
};
void main()
{
Student s;
Teacher t;
}






3.    写出下列程序的运行结果。
#include <iostream.h>
int square(int i)            {return i*i;}
float square(float i)        {return i*i;}
double square(double i)    {return i*i;}
int main()
{    int i=12;
    float f=3.0;
    double d=5.0;
    cout<<i<<'*'<<i<<'='<<square(i)<<'\n';
    cout<<f<<'*'<<f<<'='<<square(f)<<'\n';
    cout<<d<<'*'<<d<<'='<<square(d)<<'\n';
    return 0;
}


4.    写出下面程序运行的结果。
#include <iostream.h>
class B{
public:
    B(){cout<< “class B”<<endl;}
};
class X:virtual public B
{
public:
    X(){cout<< “class X”<<endl;}
};
class Y:virtual public B
{
public:
    Y(){cout<< “class Y”<<endl;}
};
class D:public X,public Y
{
public:
    D(){cout<< “class D”<<endl;}
};
void main()
{  D obj;   }



5.    写出下面程序运行的结果。
#include <iostream.h>
int main()
{
int *p;
p=new int(99);
cout<<*p++;
delete --p;
return 0;
}



6.    写出下面程序运行的结果。
#include <iostream.h>
class Base{
public:
    virtual int func() {return 0;}
};
class Derived:public Base{
public:
    int func() {return 100;}
};
void main()
{
    Derived d;
    Base &b=d;
    cout<<b.func()<<endl;
    cout<<b.Base::func()<<endl;
}



7.    写出下面程序运行的结果。
class timer{
    int seconds;
   public:
         timer()                       {seconds=0;}
         timer(char *t)                {seconds=atoi(t);}
         timer(int t)                   {seconds=t;}
     timer(int min,int sec)         {seconds=min*60+sec;}
         int gettime()                    {return seconds;}
};
main()
{
  timer a,b(10),c(“20”),d(1,10);
 cout<<“seconds1=“<<a.gettime()<endl;
 cout<<“seconds2=“<<b.gettime()<endl;
cout<<“seconds3=“<<c.gettime()<endl;
cout<<“seconds4=“<<d.gettime()<endl;
return 0;
}








8.    写出下面程序运行的结果。
class point{
  int x,y;
public:
  point(int a,int b)                   {x=a; y=b;}
  point(const point &p)              {x=2*p.x; y=2*p.y;}
void print()                          {cout<<x<<“ “<<y<<endl;}
};
main()
{
point  p1(30,40);
point p2(p1);
p1.print();
p2.print();
return 0;
}




9.    写出下面程序运行的结果。
class ab{
private:
    int a;
public:
    ab( );
};
ab::ab()
{   
cout<<“initialized \n”;
a=10;
}
void main()
{   ab s;  }



10.    写出下面程序运行的结果。
#include <iostream.h>
class test{
    private:
        int num;
    public:
        test();
        int getint()            {return num;}
        ~test();
};
test::test()                    {num=0;}
test::~test()                    {cout<<″Destructor is active″<<endl;}
void main()
{    
test x[3];
    cout<<″Exiting main″<<endl;
}
搜索更多相关主题的帖子: 改错 结果 麻烦 
2008-06-25 10:37
johenny
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2007-4-30
收藏
得分:0 
顶,期待高手的答案!
2008-06-25 10:59
lyd253261362
Rank: 1
等 级:新手上路
帖 子:91
专家分:2
注 册:2007-4-26
收藏
得分:0 
解析第10题
运行的结果是:
Exiting main
Destructor is active
Destructor is active
Destructor is active
Press any key to continue
解释:test x[3];是对象数组,实际上是三个对象。
因此,在程序退出时,会有三个“Destructor is active”。
为什么是"Exiting main"在前面那。
由于main主函数没有结束的话,对象还在生存的范围内==main()中。
当main结束时,对象就要调用相应的析构函数。
2008-06-25 17:43
lyd253261362
Rank: 1
等 级:新手上路
帖 子:91
专家分:2
注 册:2007-4-26
收藏
得分:0 
9结果。
initialized
2008-06-25 17:49
lyd253261362
Rank: 1
等 级:新手上路
帖 子:91
专家分:2
注 册:2007-4-26
收藏
得分:0 
8题结果。
30   40
60   80
拷贝构造函数。
point(const point &p)
2008-06-25 17:54
快速回复:求助!!3题改错的和10题给出程序写结果的。急。。。。。在线等。麻烦 ...
数据加载中...
 
   



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

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