473,657 Members | 2,953 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 manufactureThre e;
string dosageThree;
};
Are there always at most three alternatives? Could be a std::deque, too.
>
void printCatigory(C atigory& cat);
void printMedicine(P harmacology& pharma);
void printAlternativ e(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","AC E
Hemmer","Antihy pertensive","no ne","cave","??" ,"ÖAK"},
{"45","Lopirin" ,"Captorpril"," ACE
Hemmer","Antihy pertensive","no ne","cave","??" ,"ÖAK"},
{"46","Renitec" ,"Enalapril","A CE
Hemmer","Antihy pertensive","no ne","cave","??" ,"ÖAK"},
Lots of duplicate data. Maybe you could redesign your data model in a
way to reduce duplicate data.
int medicineSize=(s izeof medicine)/(sizeof medicine[0]);
int disorderSize=(s izeof 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 "medicineSi ze". 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_boun d.
void printMedicine(P harmacology& pharma){
cout << "Trade Name: " <<pharma.tradeN ame << endl;
cout << "Generic Name: " <<pharma.generi cName << endl;
cout << "Classification : " <<pharma.classi fication << endl;
cout << "Use: " << pharma.use << endl;
cout << "Hinwiese: " <<pharma.hinwei se << endl;
cout << "Cave: " << pharma.cave << endl;
cout << "Dosage: " << pharma.dosageFo rm << endl;
cout << "Source: " << pharma.source << endl;
cout << "------------------------------------------------------" <<
endl;
//cout << "Refrence Number: " <<pharma.refren ceNumber << 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 1174

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

Similar topics

15
1683
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 instances of my class, the whole program runs slowly in a way that I have to close the program. I have tried to create a new thread for each class, but that throws an exception , because a separated thread can't be added to a form from a child...
12
3290
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. Such things happen. The whole subsystem is going through radical changes. I don't really want to say what I think of the code just yet. That would influence the opinions of others, and I really want to know how other people view these things,...
19
352
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 c/c++? #include <stdio.h> int func() { int x; return x,x; }
6
4866
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 the html page controls the form fields that are required. It doesn't function like it's supposed to and I can leave all the fields blank and it still submits the form. Also I can't get it to transfer the file in the upload section. The file name...
7
2686
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 the goals -- the make statement is mostly syntactic sugar for:: class <name> <tuple>: __metaclass__ = <callable>
19
2429
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; //every class may have this statement self.hello = function() {
1
7287
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 to Google Map. If you don't know elisp, first take a gander at Elisp Basics. I often write travelogs on my website. If i traveled to Las Vegas, then
10
2434
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 "extend the license", so it will last another week. It consists of queries, forms, and tables, format Access 2003. Bart
12
1888
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 usual "Hello world". Took it with me to my best customer, and beleive it or not....It will not work !!!!
82
3671
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. Let's name the update method as doUpdate and stl::map read methods as getData and copyData. Since stl::map is not thread-safe, we should do synchronization by ourselves. A usable solution is to create a boost::mutex::scoped_lock object in all above...
0
8384
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8820
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8601
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5630
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4150
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4300
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1937
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1601
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.