功能无法访问.如何解决对我有帮助 [英] function is not accessible.how to solve help me

查看:78
本文介绍了功能无法访问.如何解决对我有帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在此程序中,我在银行中出错:::无法访问initial_value,
bank ::存款无法访问,bank :: display无法访问

如何解决这个问题


//标题:银行帐户

 #include   ><   conio.h  > 
 #include   <   iostream  > 
 使用 命名空间 std;
课程银行
{
私有:
  结构节点
  {
     int  ac_no;
    字符 ac_name;
    字符 ac_type;
    浮动余额;
    结构节点* next;
  }*开始;

  // 节点* start = NULL; 
  /*   bank()
  {
  开始= NULL;
  } */

   void  initial_value();
  无效存款( int  us_ac_no);
  无效提款( int );
   void  display( int );
};

无效 bank :: initial_value()
{
   int  ur_ac_no;
  字符 ur_name;
  字符 ur_ac_type;
  浮动 ur_bal;

  cout<< " << endl;
  cin>> ur_ac_no;
  cout<< " << endl;
  cin>> ur_name;

  cout<< " << endl;
  cout<< " <<   \ n"<<  << endl;
  cin>> ur_ac_type;
  cout<< " << endl;
  cin> ur_bal;

  节点* start;
  节点* temp;
  节点* last;
  temp = 节点; // 内存分配
  temp =开始;
  temp-> ac_no = ur_ac_no;
  temp-> ac_name = ur_name;
  temp-> ac_type = ur_ac_type;
  temp-> balance = ur_bal;
  temp-> next = NULL;

  如果(开始== NULL)
    开始=温度;

  其他
  {
    last = 节点;
    最后=开始;
    同时(最后一个!= NULL)
      last = last-> next;

    last-> next = temp;
  }
}


无效银行::存款( int  us_ac_no)
{
   int  dep_amount;
  节点* temp;
  temp = 节点;
  temp =开始;

  // 总浮动; 

  如果(temp-> ac_no == us_ac_no)
  {
    cout<< " << endl;
    cout<< " << temp-> ac_name<< endl ;
    cout<< " << temp->余额<< endl ;
    cout<< " << endl;
    cin> dep_amount;
    temp->平衡= temp->平衡+ dep_amount;
    cout<< " << -temp->余额;
    // 归还余额; 
  }
  其他
    cout<< " << endl;
}

无效银行::提款( int  us_ac_no)
{
   int  with_aunt;
  节点* temp;
  如果(temp-> ac_no == us_ac_no)
  {
    cout<< " << endl;
    cin>> with_aunt;

    cout<< " << endl;
    temp-> balance = temp-> balance-with_aunt;
    cout<< " << endl;
    cin> temp->平衡;
  }
}

无效 bank ::显示( int  us_ac_no)
{
  节点* temp;
  如果(temp-> ac_no == us_ac_no)
  {
    cout<< " << endl;
    cout<< " << temp-> ac_name<< endl ;
    cout<< " << temp-> ac_no<<恩德尔
    cout<< " << temp-> ac_type<<恩德尔
    cout<< " << temp->余额<< endl ;
  }
}

 int  main()
{
   int 选择;
   int  us_no;
   int  ch;
  //  clrscr(); 

  // 银行obj1(); 
  银行obj;

  cout<< " << endl;
  cout<< " " << " << endl;
  cin> ch;
  同时(ch ==  1 )
  {
    cout<< " << endl;
    cout<< " <<   \ n"<<  << " < < " << "  \ n"<<   4.详细信息"<<   5.退出"<< endl ;
    cin> choise;
    开关(选择)
    {
    案例  1 :
      obj.initial_value();
       break ;
    案例  2 :
      cout<< " << endl;
      cin>> us_no;

      obj.deposit(us_no);
       break ;
    案例  3 :
      cout<< " << endl;
      cin>> us_no;

      obj.withdrawal(us_no);
       break ;
    案例  4 :
      cout<< " << endl;
      cin>> us_no;

      obj.display(us_no);
       break ;
    案例  5 :
      cout<< " <<   \ n"<<  欢迎先生"<< endl;
       break ;
    默认:
      cout<< " << endl;
       break ;
    }
  }

  getch();
} 

解决方案

好吧,它们将不可访问.您已将它们声明为私有,这意味着您已经明确说过:此类之外的任何人都不能访问这些".

更改对公众的访问权限,然后您可以访问它们...


顺便说一句:缩进你该死的代码!它使您阅读,我们阅读以及每个人都更容易理解.我打算通过添加一个代码块(它保留格式)来改善您的问题,但是由于您没有费心去缩进,所以我没有.帮助我们,为您提供帮助!


您应该将public设为类的公共接口"(即方法).


In this program i have error in bank :: initial_value is not accessible,
bank::deposit is not accessible,bank::displayis not accessible

how to solve this problem


// Title : Bank account

#include <conio.h>
#include <iostream>
using namespace std;
class bank
{
private:
  struct node
  {
    int ac_no;
    char ac_name;
    char ac_type;
    float balance;
    struct node *next;
  }*start;

  //node *start = NULL;
  /* bank()
  {
  start = NULL;
  } */

  void initial_value();
  void deposit(int us_ac_no);
  void withdrawal(int );
  void display(int );
};

void bank :: initial_value()
{
  int ur_ac_no;
  char ur_name;
  char ur_ac_type;
  float ur_bal;

  cout<<"Enter the your New acount Number: "<<endl;
  cin>>ur_ac_no;
  cout<<"Enter the account holder Name: "<<endl;
  cin>>ur_name;

  cout<<"Enter the account type: "<<endl;
  cout<<"1. Joint account"<<"\n"<<"2. personal account"<<endl;
  cin>>ur_ac_type;
  cout<<"Initial deposit amount in your account: "<<endl;
  cin>>ur_bal;

  node *start;
  node *temp;
  node *last;
  temp = new node;	//memory allocation
  temp = start;
  temp->ac_no = ur_ac_no;
  temp->ac_name = ur_name;
  temp->ac_type = ur_ac_type;
  temp->balance = ur_bal;
  temp->next = NULL;

  if(start == NULL)
    start = temp;

  else
  {
    last = new node;
    last = start;
    while(last != NULL)
      last = last->next;

    last->next = temp;
  }
}


void bank :: deposit(int us_ac_no)
{
  int dep_amount;
  node *temp;
  temp = new node;
  temp = start;

  //float total;

  if(temp->ac_no == us_ac_no)
  {
    cout<<"Welcome to IOB bank"<<endl;
    cout<<"User Name: "<<temp->ac_name<<endl;
    cout<<"your balance: "<<temp->balance<<endl;
    cout<<"Enter your deposit amount: "<<endl;
    cin>>dep_amount;
    temp->balance = temp->balance + dep_amount;
    cout<<"your balance: "<<temp->balance;
    //return balance;
  }
  else
    cout<<"your account number is wrong"<<endl;
}

void bank :: withdrawal(int us_ac_no)
{
  int with_aunt;
  node *temp;
  if(temp->ac_no == us_ac_no)
  {
    cout<<"Enter your withdrawal Amount: "<<endl;
    cin>>with_aunt;

    cout<<"Thank you for using our bank"<<endl;
    temp->balance = temp->balance-with_aunt;
    cout<<"your balance is :"<<endl;
    cin>>temp->balance;
  }
}

void bank :: display(int us_ac_no)
{
  node *temp;
  if(temp->ac_no == us_ac_no)
  {
    cout<<"Welcome to IOB bank"<<endl;
    cout<<"Your Name: "<<temp->ac_name<<endl;
    cout<<"Your Account No: "<<temp->ac_no<<endl;
    cout<<"Your account type: "<<temp->ac_type<<endl;
    cout<<"your balance: "<<temp->balance<<endl;
  }
}

int main()
{
  int choise;
  int us_no;
  int ch;
  //clrscr();

  //bank obj1();
  bank obj;

  cout<<"If you want continue please choise option "<<endl;
  cout<<"1. yes"<<"\n"<<"2. No"<<endl;
  cin>>ch;
  while(ch == 1)
  {
    cout<<"Enter the your choise: "<<endl;
    cout<<"1. Create New Account"<<"\n"<<"2. Deposit"<<"\n"<<"3. Withdrawal"<<"\n"<<"4. Details"<<"5. Exit"<<endl;
    cin>>choise;
    switch(choise)
    {
    case 1:
      obj.initial_value();
      break;
    case 2:
      cout<<"Enter your Account Number: "<<endl;
      cin>>us_no;

      obj.deposit(us_no);
      break;
    case 3:
      cout<<"Enter your Account Number: "<<endl;
      cin>>us_no;

      obj.withdrawal(us_no);
      break;
    case 4:
      cout<<"Enter your Account Number: "<<endl;
      cin>>us_no;

      obj.display(us_no);
      break;
    case 5:
      cout<<"Thank you for accuss our bank."<<"\n"<<"Welcome sir"<<endl;
      break;
    default:
      cout<<"Wrong choise select currect choise please"<<endl;
      break;
    }
  }

  getch();
}

解决方案

Well no, they won''t be accessible. You have declared them as private, which means you have specifically said: "No one outside this class can access these".

Change the access to public, and then you can access them...


BTW: Indent your damn code! It makes it easier for you to read, us to read, and everybody to understand. I was going to improve your question by adding a code block (it preserves formatting) but since you hadn''t bothered to indent, I didn''t. Help us, to help you!


You should make public the ''public interface'' (i.e. the methods) of your class.


这篇关于功能无法访问.如何解决对我有帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆