Re: How can I make a better program from the following one
Hi!
sphenxes@gmail.com schrieb:
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <iostream>
using namespace std;
struct Catigory{
string refrenceNumber;
Why is the referenceNumber a string?
string prognose;
// This catigories is only for use latter
string catigory1;
string catigory2;
string catigory3;
string catigory4;
string catigory5;
string catigory6;
Are there always *exactly* six alternatives? The alternatives could be a
std::deque which can resize as needed.
};
struct Pharmacology{
// char disease[50];a
string refrenceNumber;
string?
struct Alternative{
string drug;
string manufacture;
string dosage;
string drugOne;
string manufactureOne;
string dosageOne;
string drugTwo;
string manufactureTwo;
string dosageTwo;
string drugThree;
string manufactureThree;
string dosageThree;
};
Are there always at most three alternatives? Could be a std::deque, too.
void printCatigory(Catigory& cat);
void printMedicine(Pharmacology& pharma);
void printAlternative(Alternative& alter);
These could be members of the respective classes.
struct Catigory disorder[]={
{"1","Epilepsy","none","none","none","none","none","none"},
{"2","Epilepsy","none","none","none","none","none","none"},
[snipped lots of data]
You could read in the data from a file. It is not good to place all the
data in the main source code. At least it could be stored in a separate
source file.
{"3","Epilepsy","none","none","none","none","none","none"},
The reference number is hard to maintain here. What if you need to
insert a record? Why keep the reference number in a "Catigory" when it
is given by the array index?
{"44","Debax","Captorpril","ACE
Hemmer","Antihypertensive","none","cave","??","??AK"},
{"45","Lopirin","Captorpril","ACE
Hemmer","Antihypertensive","none","cave","??","??AK"},
{"46","Renitec","Enalapril","ACE
Hemmer","Antihypertensive","none","cave","??","??AK"},
Lots of duplicate data. Maybe you could redesign your data model in a
way to reduce duplicate data.
int medicineSize=(sizeof medicine)/(sizeof medicine[0]);
int disorderSize=(sizeof disorder)/(sizeof disorder[0]);
These two variables could be declared "const".
/*int first;
int last;
cout << "Input your the Place of your First Characheter" << endl;
cin >> first;
cin.ignore(255,'\n');
cout << "Input your the Place of your Last Characheter" << endl;
cin >> last;
cin.ignore(225,'\n');
You could remove the "cin.ignore" calls if you place a "cin >>
noskipws;" in front of your program.
switch(menu){
case 1:
Put the source code in the "case"s into separate functions. Make "main"
shorter.
cout << " " << endl;
cout << " " << endl;
This code is in every "case". Place it in front of the "switch".
do{
string generic;
cout << "Input the genericName" << endl;
getline(cin, generic);
for (int i=0; i<1652;i++){
Replace the "1652" by "medicineSize". You could easily forget to update
the number otherwise.
string s2 =medicine[i].genericName;
// if (generic.substr(first, last) == s2.substr(first,last) ){
if (generic.substr(0, 4) == s2.substr(0,4) ){
Use a associative container for lookup, like std::map. Or use a more
efficient lookup algorithm, like std::lower_bound.
void printMedicine(Pharmacology& pharma){
cout << "Trade Name: " <<pharma.tradeName << endl;
cout << "Generic Name: " <<pharma.genericName << endl;
cout << "Classification: " <<pharma.classification << endl;
cout << "Use: " << pharma.use << endl;
cout << "Hinwiese: " <<pharma.hinweise << endl;
cout << "Cave: " << pharma.cave << endl;
cout << "Dosage: " << pharma.dosageForm << endl;
cout << "Source: " << pharma.source << endl;
cout << "------------------------------------------------------" <<
endl;
//cout << "Refrence Number: " <<pharma.refrenceNumber << endl;
}
Only use "endl" at the end of the function. "endl" will be much slower than
cout << '\n'
because it will wait until the data is written to the screen, it will
flush the output buffer. This is needless when you output further data
immediately.
These advises should give you some work to do.
Regads,
Frank