我需要幫助來調試此程序。調試此C++程序
// VirtualFN.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <conio.h>
#include <string>
#include <iomanip>
using namespace std;
enum isautostart { no,yes };
class vehicle {
protected:
static int noofvehicles;
string vehiclename;
long long int price;
isautostart autostart;
public:
vehicle():price(0),autostart(no),vehiclename("N/A")
{
noofvehicles++;
}
vehicle (vehicle& tempveh){
vehiclename = tempveh.vehiclename;
autostart = tempveh.autostart;
price = tempveh.price;
}
virtual void getdataofvehicle(){
string tempcarname;
char check[15];
cout<< "\nPlease enter the name of vehicle :";
getline(cin,tempcarname);
vehiclename = tempcarname;
/*******************************************************/
while(true){
cout<< "Please enter the price of the car :"; cin>>setw(14)>>check;
if(atoi(check)){
price = atoi(check);
break;}
else{
cout<< "you didn't enter the integer number , Try again"<<endl;
}
}
/*******************************************************/
char bools;
cout <<"Vehicle has autostart function ? : (y/n)"; cin >> bools;
if(bools == 'y'){
autostart = yes;
}
else { autostart = no; }
}
virtual void displaycardata() {
cout<< "\nName of vehicle is :" << vehiclename;
cout<< "\nPrice of the vehicle is : $" <<price;
if(autostart){
cout<< "\nThis vehicle is autostart.";}
else{
cout<< "\nThis vehicle is not autostart.";}
}
static void displaynoofcars(){
cout<<"\nNo of cars in warehouse are :" << noofvehicles;
}
};
int vehicle::noofvehicles = 0;
class mercedez : public vehicle {
string color;
public:
mercedez(): vehicle() {
color = "N/A";}
void getdataofvehicle() {
vehicle::getdataofvehicle();
cout<<"\nPlease enter the color of the car :";
cin >> color;
}
void displaycardata(){
vehicle::displaycardata();
cout<<"\nThe color of the car is:" << color;
}
};
int main()
{
vehicle *v1;
vehicle *v2;
mercedez a;
v1 = new vehicle;
vehicle::displaynoofcars();
v2 = new mercidez;
vehicle::displaynoofcars();
v1->getdataofvehicle();
v1->displaycardata();
v2->getdataofvehicle();
v2->displaycardata();
getch();
return 0;
}
現在
當繼承的類梅塞德斯嘗試通過V2-執行車輛的getdataofvehicle> getdataofvehicle();基類的
getdataofvehicle功能部分並不需要輸入時,僅diaplays「請輸入汽車的價格」,並直接跳轉到: COUT < <「請輸入汽車的價格:」; CIN >>運輸及工務局局長(14)>>檢查;
誰能請調試這一點,並告訴我這是爲什麼發生的
任何幫助是非常讚賞
'長的長整型價格;'哇'那些可以mercidez' O_O是 – Dmitry 2010-08-12 19:11:31
@Carl Norum時貴:這不是我的功課,我正在學習C++,使我可以和maya api一起工作(我是一名學習gfx藝術家) @Dmitry:是的,他們對我來說至少是大聲笑 – M3taSpl0it 2010-08-12 19:24:04
小建議:使用C++ caml-case風格命名事物。 getDataOfVehicle比getdataofvehicle更易於閱讀。 – 2010-08-12 19:51:26