I'm fairly new to programming and I was given an assignment:
Define a pharmacy type class containing fields - unique name (up to 40 characters), purpose (up to 30 characters), side effects (yes or no), quantity available at the pharmacy store (integer ), unit cost of the medicine (two decimal places), date of manufacture.
Write a program using member functions that:
enter the pharmacy data set in a one-dimensional array of 1000 drugs;
finds the average value of all drugs that have side effects;
sort by drug name in alphabetical order;
identifies the drug with the highest value among drugs whose names start with the letters "A" and "C";
I have tried to do the code myself, but I haven't gotten any luck so far. I've tried referencing code from several forums online too, but there's been no luck so far.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
#include <iostream>
#include <string.h>
using namespace std;
class pharmacy
{
char purp[30];
char sf[3];
int quantity;
double price;
public:
char name[40];
pharmacy();
~pharmacy();
void display();
friend void sort_price(int, pharmacy[]);
};
pharmacy::pharmacy()
{
cin.sync();
cout<<"Input drug name: ";
cin.getline(name, 40);
cout<<"Input purpose: ";
cin.getline(purp, 30);
cout<<"Are there side effects: ";
cin.getline(sf, 3);
cout<<"Input drug quantity: ";
cin>>quantity;
cout<<"Input drug price: ";
cin>>price;
}
void pharmacy::display()
{
cout<<"Drug name: "<<name<<endl;
cout<<"Purpose: "<<purp<<endl;
cout<<"Side effects: "<<sf<<endl;
cout<<"Drug quanity: "<<quantity<<endl;
cout<<"Drug price: "<<price<<endl;
}
pharmacy::~pharmacy()
{
cout<<"~pharmacy"<<endl;
};
void sort_name(int br, pharmacy A[])
{
pharmacy swap;
for(int i=0; i<br-1; i++)
for(int j=0; j<br-i-1; j++)
if(strcmp(A[j].ime, A[j+1].ime)>0)
{
swap=A[j];
A[j]=A[j+1];
A[j+1]=swap;
}
}
int main()
{
system ("pause");
return 0;
}
|
Apologies if any of the used terms are not correct, it's been translated using Google Translate. If anyone can provide a working code or a similar code to the one that is being asked of me so that I can reference it, I'll be eternally grateful! Please help me, I have almost no time left!