Click here to Skip to main content
15,881,559 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
  1  #include <iostream.h>
  2  #include <conio.h>
  3  class menu
  4  {
  5  	char select_menu;
  6  	public:
  7  	void getdata()
  8  	{
  9  		cout<<"Select menu";
 10  	}
 11  		do{
 12  			cout<<"1:Create records"<<endl;
 13  			cout<<"2:Edit the records"<<endl;
 14  			cout<<"3:Search the records"<<endl;
 15  			cout<<"4:Delete the records"<<endl;
 16  			cout<<"5:Save records"<<endl;
 17  			cout<<"6:Exit records"<<endl;
 18  			cout<<"======================"<<endl;
 19  			cout<<"Select any one menu"<<endl;
 20  		}while(select_menu != 5);
 21  	char name[20];
 22  	char branch[20];
 23  	int en_no;
 24  
 25  	void created_record()
 26  	{
 27  		int choice;
 28  		cout<<"How many student do you want to enter:"<<endl;
 29  		cin>>choice;
 30  		for(int i=0;i<=choice;i++)
 31  		{
 32  			cout<<"Enter data of student:"<<endl;
 33  			cout<<"Enter your name:"<<endl;
 34  			cin>>name;
 35  			cout<<"Enter your branch"<<endl;
 36  			cin>>branch;
 37  			cout<<"Enter your enrollment no"<<endl;
 38  			cin>>en_no;
 39  		}
 40  	}
 41  
 42  	void edit_the_record()
 43  	{
 44  		cout<<"Enter the enrollment no of the student which you want to search :"<<endl;
 45  		cin>>enrollment_no;
 46  		for(int i=0;i<int total;i++)
 47  		{
 48  			if(enrollment_no == en_no)
 49  			{
 50  				cout<<"Previous data:"<<endl;
 51  				cout<<"Data of student:"<<endl;
 52  				cout<<"Name:"<<endl;
 53  				cin>>name;
 54  				cout<<"Branch:"<<endl;
 55  				cin>>branch;
 56  				cout<<"Enrollment no:"<<endl;
 57  				cin>>en_no;
 58  				cout<<"UPdata new data"<<endl;
 59  				cout<<"enter name"<<endl;
 60  				cin>>name;
 61  				cout<<"Enter your branch"<<endl;
 62  				cin>>branch;
 63  				cout<<"Enter your enrollment no:"<<endl;
 64  				cin>>enrollment_no;
 65  
 66  			}
 67  		}
 68  	}
 69  	void search_record()
 70  	{
 71  		cout<<"enter enrollment no of studentwhich you want to search:"<<endl;
 72  		cin>>enrollment_no;
 73  		for(inti=0;i=int total;i++)
 74  		{
 75  			cout<<"Data of student:"<<endl;
 76  			cout<<"enter name:"<<endl;
 77  			cin>>name;
 78  			cout<<"enter branch:"<<endl;
 79  			cin>>branch;
 80  			cout<<"enter your enrollment no:"<<endl;
 81  			cin>>en_no;
 82  		}
 83  	}
 84  	void delete_record()
 85  	{
 86  		int a;
 87  		cout<<"press 1: delete the total record"<<endl;
 88  		cout<<"press 2: delete specific record"<<endl;
 89  		cin>>a;
 90  		if(a==1)
 91  		{
 92  			int total=0;
 93  			cout<<"All record Deleted"<<endl;
 94  		}
 95  		else(a==2)
 96  		{
 97  			int enrollment_no;
 98  			cout<<"enter enrollment no whoch you want to delete"<<endl;
 99  			cin>>en_no;
100  			for(int i=0;i<int total;i++)
101  			{
102  				if(enrollment_no==en_no)
103  				{
104  					cout<<"your record is deleted..."<<endl;
105  				}
106  			}
107  		}
108  	}
109  
110  
111  };
112  void main()
113  {
114  	clrscr();
115  	menu m;
116  	switch (select_menu)
117  	{
118  		case 1:create_record();
119  			break;
120  		case 2:edit_record();
121  			break;
122  		case 3:search_record();
123  			break;
124  		case 4:delete_record();
125  			break;
126  		case 5:save_record();
127  			break;
128  		case 6:exit_the_record();
129  			break;
130  
131  	}
132  	getch();
133  }


What I have tried:

i have tried by placing switch case inside the main() class but it shows many errors and warnings and the code has not even run once.
Posted
Updated 23-Jul-22 6:17am
v3
Comments
0x01AA 23-Jul-22 8:23am    
Looks like something went wrong while posting the code. Use 'Improve question' and post your code again.
thesnehad 23-Jul-22 8:27am    
thanks for help
thesnehad 23-Jul-22 8:30am    
is the code understandable now?
0x01AA 23-Jul-22 8:35am    
Yes, now the code is readable.
thesnehad 23-Jul-22 8:42am    
any ideas how to solve?

If this is to become a standards-compliant C++ program, the correct headers should be used:
Neither <iostream.h> nor <conio.h> exist under C++.
//#include <iostream.h>	  
#include <iostream>
// #include <conio.h>
using std::cout;

The getdata() member function cannot work like this.
C++
void getdata()
{
  cout << "Select menu";
}
do {
...
} while (select_menu != 5);

On the one hand, curly brackets are wrong, on the other hand, the select_menu variable is not read in, so the do-while loop does not work. It would be better to separate the declaration of the class from the implementation. Preferably in two separate files.
C++
// menu.h
class menu
{
public:
	int getMenu();
	// ...
private:
	char select_menu;
	char name[20];
	char branch[20];
	int en_no;
};

C++
// menu.cpp
int menu::getMenu()
{
   cout << "Select menu\n";
   // ...
   return select_menu;
}


//Edit:
Since several similar data records are to be managed later on, it makes sense to manage them in a separate structure or class.
C++
typedef struct {
	std::string name;
	std::string branch;
	int en_no;
} studentdata;

Containers such as string, array, vector, ... are preferably used under C++.
 
Share this answer
 
v3
Comments
0x01AA 23-Jul-22 9:39am    
Have my 5.
I don't agree with you that separating declaration and implementation will help. That's why I love c#. But that is only personal preference :-)
merano99 23-Jul-22 10:05am    
thanks ;-)
thesnehad 23-Jul-22 11:34am    
Thanks for the help!!
But my task is to do this program under iostream header file
merano99 23-Jul-22 14:30pm    
My condolences that you have to use an outdated compiler. It may be that my suggestions will also work with your C++-like compiler, but some things may also not work.
thesnehad 24-Jul-22 5:45am    
okay!!
I should not doing it but I do it. I post here your code which is compilable (see below, several TODO comments). But even the code compiles it does not mean it works. It is very questionable whether it will help.

I strongly assume you did not write that code by yourself. This because if one write code one do it step by step and when you are doing it step by step you seldom end in a mess like this ;)

I suggest you do start from scratch and first think about what are the requirements and how you would solve that step by step.

Here the compialable code. Most probably not really helpfull, but maybe it helps you to sove some basic mistakes ;)

  1  #include <iostream>
  2  #include <conio.h>
  3  using namespace std;
  4  class menu
  5  {
  6      private:
  7  	char select_menu;
  8  	char name[20];
  9  	char branch[20];
 10  	int en_no;
 11  	int total= 0; /* TODO!! */
 12  
 13  	public:
 14  	int getMenu()
 15  	{
 16  		cout<<"Select menu";
 17  		do{
 18  			cout<<"1:Create records"<<endl;
 19  			cout<<"2:Edit the records"<<endl;
 20  			cout<<"3:Search the records"<<endl;
 21  			cout<<"4:Delete the records"<<endl;
 22  			cout<<"5:Save records"<<endl;
 23  			cout<<"6:Exit records"<<endl;
 24  			cout<<"======================"<<endl;
 25  			cout<<"Select any one menu"<<endl;
 26  		//}while(select_menu != 5);
 27          } while ((select_menu < '1') || (select_menu > '6'));
 28        return  toascii(select_menu) - 48;
 29  	}
 30  	void created_record()
 31  	{
 32  		int choice;
 33  		cout<<"How many student do you want to enter:"<<endl;
 34  		cin>>choice;
 35  		for(int i=1;i<=choice;i++)
 36  		{
 37  			cout<<"Enter data of student:"<<endl;
 38  			cout<<"Enter your name:"<<endl;
 39  			cin>>name;
 40  			cout<<"Enter your branch"<<endl;
 41  			cin>>branch;
 42  			cout<<"Enter your enrollment no"<<endl;
 43  			cin>>en_no;
 44  		}
 45  	}
 46  
 47  	void edit_the_record()
 48  	{
 49  	    int enrollment_no;
 50  		cout<<"Enter the enrollment no of the student which you want to search :"<<endl;
 51  		cin>>enrollment_no;
 52  		for(int i=0; i < total;i++)
 53  		{
 54  			if(enrollment_no == en_no)
 55  			{
 56  				cout<<"Previous data:"<<endl;
 57  				cout<<"Data of student:"<<endl;
 58  				cout<<"Name:"<<endl;
 59  				cin>>name;
 60  				cout<<"Branch:"<<endl;
 61  				cin>>branch;
 62  				cout<<"Enrollment no:"<<endl;
 63  				cin>>en_no;
 64  				cout<<"UPdata new data"<<endl;
 65  				cout<<"enter name"<<endl;
 66  				cin>>name;
 67  				cout<<"Enter your branch"<<endl;
 68  				cin>>branch;
 69  				cout<<"Enter your enrollment no:"<<endl;
 70  				cin>>enrollment_no;
 71  
 72  			}
 73  		}
 74  	}
 75  	void search_record()
 76  	{
 77  	    int enrollment_no;
 78  		cout<<"enter enrollment no of studentwhich you want to search:"<<endl;
 79  		cin>>enrollment_no;
 80  		for(int i=0; i= total;i++)
 81  		{
 82  			cout<<"Data of student:"<<endl;
 83  			cout<<"enter name:"<<endl;
 84  			cin>>name;
 85  			cout<<"enter branch:"<<endl;
 86  			cin>>branch;
 87  			cout<<"enter your enrollment no:"<<endl;
 88  			cin>>en_no;
 89  		}
 90  	}
 91  	void delete_record()
 92  	{
 93  		int a;
 94  		cout<<"press 1: delete the total record"<<endl;
 95  		cout<<"press 2: delete specific record"<<endl;
 96  		cin>>a;
 97  		if(a==1)
 98  		{
 99  			int total=0;
100  			cout<<"All record Deleted"<<endl;
101  		}
102  		else if (a==2)
103  		{
104  			int enrollment_no;
105  			cout<<"enter enrollment no whoch you want to delete"<<endl;
106  			cin>>en_no;
107  			for(int i=0; i < total;i++)
108  			{
109  				if(enrollment_no==en_no)
110  				{
111  					cout<<"your record is deleted..."<<endl;
112  				}
113  			}
114  		}
115  	}
116  
117  
118  };
119  
120  int main()
121  {
122  	/*clrscr();  not standard C++ */
123  	menu m;
124  	switch (m.getMenu())
125  	{
126  		case 1:m.created_record();
127  			break;
128  		case 2:m.edit_the_record();
129  			break;
130  		case 3:m.search_record();
131  			break;
132  		case 4:m.delete_record();
133  			break;
134  		/*TODO
135  		case 5:m.save_record();
136  			break;
137  		*/
138  		
139  		/* TODO
140  		case 6:m.exit_the_record();
141  			break;
142  		*/
143  
144  	}
145  	/*getch();  not standard C++*/
146  	string temp;
147  	getline(cin, temp);
148  	return 0;
149  }
 
Share this answer
 
v3
Comments
thesnehad 23-Jul-22 12:24pm    
Thanks a lot for your help.
Actually I took ideas from the sample code and tried to write it by my self but unfortunately it's going the way opposite it had thought.
And after all the errors which I saw my mind didn't work
Thanks for that I will try hard to work on that.
0x01AA 23-Jul-22 12:36pm    
And I think you should start with some more easy examples to get familiar with c++.

All the best and stay tuned ;)
thesnehad 23-Jul-22 23:42pm    
okay thanks a lot!!

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