| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 747 人关注过本帖
标题:求助!!3题改错的和10题给出程序写结果的。急。。。。。在线等。麻烦高手了 ...
取消只看楼主 加入收藏
a188a100
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2008-6-25
收藏
 问题点数:0 回复次数:0 
求助!!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
快速回复:求助!!3题改错的和10题给出程序写结果的。急。。。。。在线等。麻烦 ...
数据加载中...
 
   



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

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