【发布时间】:2021-08-26 09:47:48
【问题描述】:
在下面的代码中,我做了两个类,第二个类继承自第一个类。但是,当我调用 getdata 函数时。它跳过输入,我尝试使用 cin.ingnore() 和 cin>>ws,但我仍然遇到相同的错误。它运行正常,直到“输入姓氏”,但之后,它只打印所有其他内容而不接受输入。
#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;
class RegistrationModule{
protected:
string Firstname;
string Lastname;
double cnic;
double contact;
string address;
static double challanno;
public:
RegistrationModule(){
Firstname = "";
Lastname = "";
cnic=0;
address = "";
contact=0;
challanno++;
}
};
double RegistrationModule::challanno=105487;
class monthlyentry : public RegistrationModule{
public:
void getdata(){
cout<<"Enter First Name"<<endl;
getline(cin,Firstname);
cin.ignore();
cout<<"Enter Last Name"<<endl;
getline(cin,Lastname);
cin.ignore();
cout<<"Enter your CNIC: "<<endl;
cin>>cnic;
cin.ignore();
cout<<"Enter your Address: "<<endl;
getline(cin,address);
cout<<"Enter your contact number: "<<endl;
cin>>contact;
cout<<"Your Challan Number is: "<<challanno<<endl;
}
};
int main(){
int size;
monthlyentry a;
a.getdata();
}
【问题讨论】:
标签: c++ class oop inheritance