473,376 Members | 1,218 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,376 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 1148

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....
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.