Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>


class Patient
{
	int id;
	char name[30];
	float age;
	char sex[6];
	int room_no;

	public:
		void show();
		void add();
		void search(Patient*p);
};


void Patient::show(){
	cout<<"\n Patient Name :  "<<name;
	cout<<"\n Patient ID :  "<<id;
	cout<<"\n Patient Age  :  "<<age;
	cout<<"\n Sex          :  "<<sex;
	cout<<"\n Room No.     :  "<<room_no;
	cout<<"\n Patient name has been registered";
}


void Patient::add(){
	cout<<"\n -------------------------------";
	cout<<"\n Enter Patient Details";
	cout<<"\n -------------------------------";
	cout<<"\n Patient Name :  ";
	cin>>name;
	cout<<"\n Patient ID :  ";
	cin>>id;
	cout<<"\n Patient Age  :  ";
	cin>>age;
	cout<<"\n Sex          :  ";
	cin>>sex;
	cout<<"\n Room No.     :  ";
	cin>>room_no;

}


void Patient::search(Patient*p)
	{
	int i,confirm=0,iid;
	cout<<"\nEnter Patient's ID :  ";
	cin>>iid;
	for(i=0;i<10;i++)
	{
		if(iid==p[i].id)
		{
			confirm=1;
			break;
		}
	}
	if(confirm==1)
	{
		cout<<"Patient is in room number "<<p[i].room_no;
	}
	else
	{
		cout<<"Patient not found";
	}
}


void main(){
	Patient p[10];
	clrscr();
	p[1].add();
	p[1].show();
	p[1].search(p);
	getch();
	int n;
	do{
		cout<<"Welcome to Hospital Patient Management"<<endl;
		cout<<"Press 1 >>Add Patient\n";
		cout<<"Press 2 >>Search for Patient\n";
		cout<<"\nEnter Number :  ";
		cin>>n;
		switch(n){
			case 1:
				p[1].add();
				break;
			case 2:
				p[1].search();
				break;
			case 3:
				return;
		}
	}while(n!=3);
	cout<<"Thank You...!";
}


What I have tried:

Tried everything cant understand please help......
Posted
Updated 14-Mar-22 5:57am

Look at your case statement
C++
case 2:
				p[1].search();
You have not defined any override of search that does not take any parameters. Look at your Patient class
C++
class Patient
{
	int id;
	char name[30];
	float age;
	char sex[6];
	int room_no;

	public:
		void show();
		void add();
		void search(Patient*p);
};
You could get around it with
C++
case 2:
				p[1].search(&p[1]);
but I think you need to do some rethinking
 
Share this answer
 
Your code is very C-like.
You could take more advantage from C++ features and library.
Try, for instance:
C++
#include<iostream>
#include <vector>
#include <algorithm>
using namespace std;

class Patient
{
  int id;
  string name;
  //...

public:
  Patient( int id, string name /*, ...*/):id(id), name(name){}
  int get_id() const { return id;}
  friend ostream & operator <<(ostream & os, const Patient & p); //i.e.  'show'
};

ostream & operator << (ostream & os, const Patient & p)
{
  os << "\n Patient Name : " << p.name;
  os << "\n Patient ID : " << p.id;
  //..
  return os;
}

void add_patient(vector <Patient> & vp)
{
  string name;
  int id;
  cout<<"\n -------------------------------";
  cout<<"\n Enter Patient Details";
  cout<<"\n -------------------------------";
  cout<<"\n Patient Name :  ";
  cin>>name;
  cout<<"\n Patient ID :  ";
  cin >> id;
  //..
  vp.emplace_back(Patient(id, name));
}


void search_patient( const vector <Patient> & pv, int id)
{
  auto it = find_if(pv.begin(), pv.end(), [id](Patient p){ return p.get_id() == id;});
  if ( it == pv.end() )
    cout << "not found.\n";
  else
    cout << "found: " << *it << "\n";
}


int main()
{
  vector<Patient> pv;

  int n;
  do
  {
    cout<<"Welcome to Hospital Patient Management"<<endl;
    cout<<"Press 1 >>Add Patient\n";
    cout<<"Press 2 >>Search for Patient\n";
    cout<<"\nEnter Number :  ";
    cin >> n;
    switch(n)
    {
      case 1:
        add_patient(pv);
        break;
      case 2:
        {
          int id;
          cout << "\nplease enter the id : ";
          cin >> id;
          search_patient(pv, id);
        }
        break;
      case 3:
        break;
    }
  }while(n<3);
  cout<<"Thank You...!";
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900