标题:C++ 汽车类的问题![声明,本人表述能力差,各位多担待!]
取消只看楼主
色盲怎注册
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2011-3-23
结帖率:0
已结贴  问题点数:0 回复次数:2 
C++ 汽车类的问题![声明,本人表述能力差,各位多担待!]

用c++的知识,写一个汽车类,要求三个方法 run() stop() speedup().四个属性。要在启动汽车后才可以停止和加速。并且速度的起始值是50.每加一次,速度加5,并且显示此时汽车的状态。先按停止,提示汽车没启动。我自己写了个,杯具呀!我写的暂时没有写颜色重量等四个属性,纠结在三个成员函数对于功能的实现上。
求指导!讨论!BS,我深刻意识到我大学的时光白白浪费了。。。。
程序代码:
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
#include <string>
using namespace std;


class CCar
{
    public:
      void carRun()
      {
        //string c;
        //cout<<"请输入r/R后回车启动汽车:";
        //cin>>c;
        cout<<"汽车启动成功.初始速度:50KM/S。"<<endl<<endl;
       };
      
     void carStop()
      {
        //string s;
        cout<<"汽车已停止前进."<<endl;
      };
      int carspeedUp()
      {
       //
      //    {
          //string s;
          //cin>>s;
           //speed =50;
        
            int i;
           // i = 50;
                i = i+5;
            cout<<"现在速度是:"<<i<<"KM/S."<<endl;    
            return i;
         // }
      }
    //private:
    //int speed;
};

int main()
{   string c;
  int speed;
  int i;
  i=50;
        // cout<<"请输入r/R启动汽车:";
        //cin>>c;
    cout<<"按r/R后回车启动汽车,启动后按s/S停止前进,按a/A加速:"<<endl; 

    CCar car1;
  
  while (c!="e"||c!="E")
    {  
         cout<<endl;
         cin>>c;
          cout<<endl;
         cout<<"请继续进行操作:";
         cout<<endl
         <<"启动后按s/S停止前进,按a/A加速:"
         <<endl
         <<"按e/E键退出。"<<endl<<endl;
       
         if (c=="R"||c=="r" )
           {   
           car1.carRun();
           //cout<<"汽车启动成功.现在速度是50km/s。"<<endl<<endl;
         }
        else if (c=="s"||c=="S")
            {cout<<"先按r/R启动汽车。" ;
             cout<<"汽车没有正常启动!";
            }

     //cout<<"下一步操作:" ;
     //cin>>c;
    
         if (c=="s"||c=="S")
           {
               car1.carStop();
           }
              
                   // {
           //  cout<<"汽车已停止前进."<<endl<<endl;
            //}
          //else
          //    {
              //   cout<<"请先启动汽车。" <<endl;
            // }
           
     if (c=="a"||c=="A")
        {
         car1.carspeedUp();
        }
    
     if (c=="e"||c=="E")
    
    
     break;
//cout<<"下一步操作:" ;
  //    cin>>c;
    
    
    }}
    
    
  /* for (speed=50;speed<=300;speed++)
        
{
    cin>>c;
    if (c=="s"||c=="S")
          {
          cout<<"汽车已停止前进."<<endl<<endl;
          }
       else {
           cout<<"请先启动汽车。" ;
       }
       if  (c=="a"||c=="A")
         {car1.carspeedUp(i);
         cout<<speed;}
         else {cout<<"请先启动汽车。"; }
       }
        
    }*/
   
   
//{for ((c=="R"||c=="r")&&(su=="s"||su="S")    )
//{
//cout<<"汽车已停止前进."<<endl<<endl;   
//}}
//}


多谢了!分不多!

[ 本帖最后由 色盲怎注册 于 2011-3-23 14:19 编辑 ]
搜索更多相关主题的帖子: color 声明 speedup 汽车 能力 
2011-03-23 14:07
色盲怎注册
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2011-3-23
得分:0 
冒死附上要求原文!事先说一下,这只是类的最基本应用,最好不要用虚函数等后续深入的知识来解答。对于原文,都是满篇的“了解”,“知道”。我看了五天了。任务做到后面的, 这个一直不会。我杯具!同求提高c++水平的方法!
Design a class with C++.
    Classes are a software construct that can be used to emulate a real world object. For instance, a software model of a car, a car "class", might contain data about the type of car and abilities such as accelerate or decelerate. A class is a programmer defined data type that has data, its members, and abilities, its methods. An object is a particular instance of a class.
    Please design a car ‘class’, include constructor and destructor, four properties: weight, color, speed and runstatus, three methods: run(), stop(), speedup(). The default speed is 0, Run() will change the car’s runstatus from ‘stop’ to ‘run’ and set the speed=50, stop() will change the runstatus from ‘run’ to ‘stop’ and set the speed=0, speedup() only be used when the car is running, it will increase the speed, add 5 one time, give some tips when the car’s properties changed. It is suggested to implement a method to show the car’s current properties.
    You should know three important concepts, Encapsulation, Inheritance and Polymorphism.


在多说一句,在C FREE 下运行的。加速函数的效果那叫一个杯具,代码肯定是有问题的。帮帮我吧!

[ 本帖最后由 色盲怎注册 于 2011-3-23 14:14 编辑 ]
2011-03-23 14:11
色盲怎注册
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2011-3-23
得分:0 
回复 3楼 韵侣逍遥
我这段代码虽然是自己敲的,但也算是东拼西凑的,觉得自己对程序本身完全没有想法的。。。。。。。谢谢你的回复!想自身有进步呀!
2011-03-24 08:36



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-334503-1-1.html




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

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