468,103 Members | 1,265 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,103 developers. It's quick & easy.

Re: How can I make a better program from the following one

Hi!

sp******@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","??","ÖA K"},
{"45","Lopirin","Captorpril","ACE
Hemmer","Antihypertensive","none","cave","??","ÖA K"},
{"46","Renitec","Enalapril","ACE
Hemmer","Antihypertensive","none","cave","??","ÖA K"},
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
Jun 27 '08 #1
0 954

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

15 posts views Thread by ham-z | last post: by
12 posts views Thread by Steven T. Hatton | last post: by
19 posts views Thread by centurian | last post: by
6 posts views Thread by scottyman | last post: by
7 posts views Thread by Steven Bethard | last post: by
19 posts views Thread by zzw8206262001 | last post: by
1 post views Thread by xahlee | last post: by
12 posts views Thread by =?Utf-8?B?S2plbGw=?= | last post: by
82 posts views Thread by Bill David | last post: by
1 post views Thread by Solo | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.