473,410 Members | 1,872 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,410 software developers and data experts.

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 1151

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: ham-z | last post by:
I have written the following Win app in VB.NET 2003 . The class is simply picture boxes that behave in a random order after they have been instantiated and added to a form. When I create 15 or more...
12
by: Steven T. Hatton | last post by:
This is something I've been looking at because it is central to a currently broken part of the KDevelop new application wizard. I'm not complaining about it being broken, It's a CVS images. ...
19
by: centurian | last post by:
I have compiled following program with g++/gcc 3.3.1 and "MS Visual C++ 6" and it ran without any errors. Does this thing make any sense? Is it of some use or some problem with grammar/CFG of...
6
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of...
7
by: Steven Bethard | last post by:
I've updated PEP 359 with a bunch of the recent suggestions. The patch is available at: http://bugs.python.org/1472459 and I've pasted the full text below. I've tried to be more explicit about...
19
by: zzw8206262001 | last post by:
Hi,I find a way to make javescript more like c++ or pyhon There is the sample code: function Father(self) //every contructor may have "self" argument { self=self?self:this; ...
1
by: xahlee | last post by:
Elisp Tutorial: Make Google Earth Xah Lee, 2006-12 This page shows a example of writing a emacs lisp function that creates a Google Earth file, and creates a link to the file, as well a link...
10
by: AA Arens | last post by:
I do have a database with customer info in it. To avoid it will be taken out of our office, is it possible to make it not-readable after a certain period? then every let say seven days, I needs to...
12
by: =?Utf-8?B?S2plbGw=?= | last post by:
Hello I've taken a four days training in C#, very good training, experienced teacher and all that, very positive. Went home spent a week making my first application, slightly more than the...
82
by: Bill David | last post by:
SUBJECT: How to make this program more efficient? In my program, a thread will check update from server periodically and generate a stl::map for other part of this program to read data from....
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.