main ny Medical Store Management System project bnaya socha ap k sth bhi share kr du
SCREEN SHOTS:
[ATTACH][ATTACH][/ATTACH][/ATTACH]
CODE:
#include <iostream>
#include <fstream>
#include <windows.h>
#include <string>
#include <sstream>
using namespace std;
int main();
ofstream fout;
ifstream fin;
class Medicine{
public:
string name;
string weight;
string type;
string expiryDate;
double price;
Medicine(){
price = 0.0;
}
};
void DisplyMed(Medicine m){
cout << endl;
cout << "\tMedicine : " << m.name << endl;
cout << "\tType : " << m.type << endl;
cout << "\tWeight : " << m.weight << endl;
cout << "\tExpiry Date : " << m.expiryDate << endl;
cout << "\tPrice Rs. " << m.price << endl;
}
// Node for Linked list
class mNode{
public:
Medicine m;
mNode *next;
mNode(){
next = NULL;
}
};
//Linked List class for Medicine
class mList{
mNode *head;
public:
mList(){
head = NULL;
}
void addTofile();
bool isEmpty();
void addMedicine(Medicine newMedicine);
void searchMedicine(string mName);
void DisplayMed(string mType);
void removeMedicine(string mName);
void showM_List();
void countMedicine();
}newList;
// to check list is empty or not
void mList::addTofile(){
mNode *temp = head;
while (temp != NULL){
Medicine m = temp->m;
fout << temp->m.name << "," << temp->m.type << "," << temp->m.weight << "," << temp->m.expiryDate << temp->m.price << "\n";
temp = temp->next;
}
fout.close();
delete temp;
}
bool mList::isEmpty(){
return(head == NULL);
}
// to add medicine at end
void mList::addMedicine(Medicine newMedicine){
if (head == NULL){
head = new mNode;
head->m = newMedicine;
head->next = NULL;
}
else if (head->next == NULL){
head->next = new mNode;
head->next->m = newMedicine;
head->next->next = NULL;
}
else{
mNode *temp = head;
while (temp->next != NULL){
temp = temp->next;
}
temp->next = new mNode;
temp->next->m = newMedicine;
temp->next->next = NULL;
}
}
// searching medicine by name
void mList::searchMedicine(const string mName){
if (isEmpty()){
cout << "\tEmpty List!" << endl;
}
else{
mNode *temp = head;
bool found = false;
while (temp != NULL && !found){
if (temp->m.name == mName){
found = true;
break;
}
else{
temp = temp->next;
}
}
if (found){
DisplyMed(temp->m);
}
else{
cout << "/tMedicine not Found!" << endl;
}
}
}
// to display medicine of same type
void mList:isplayMed(string mType){
if (isEmpty()){
cout << "\tEmpty List!" << endl;
}
else{
mNode *temp = head; bool c = false;
while (temp != NULL){
if (temp->m.type.compare(mType) == 0){
c = true;
DisplyMed(temp->m);
cout << endl;
}
temp = temp->next;
}
delete temp;
if (!c){
cin.get();
cout << "\tNo Medicines found of " << mType << " Type."
<< endl;
Sleep(1000);
}
}
}
// to display all Medicines in the list
void mList::showM_List(){
if (isEmpty()){
cout << "Empty List!" << endl;
}
else{
mNode *temp = head;
while (temp != NULL){
DisplyMed(temp->m);
temp = temp->next;
}
delete temp;
}
}
void mList::removeMedicine(string mName){
if (isEmpty()){
cout << "\tEmpty List!" << endl;
}
else if ((head->next) == NULL && (head->m.name == mName)){
head = NULL;
cout << "\tMedicine Deleted!" << endl;
}
else if (head->m.name == mName){
head = head->next;
cout << "\tMedicine Deleted!" << endl;
}
else{
mNode *temp = head;
mNode *prev = NULL;
bool found = false;
while (temp != NULL && !found){
if (temp->m.name == mName){
found = true;
break;
}
prev = temp;
temp = temp->next;
}
if (found){
prev->next = temp->next;
cout << "\tMedicine Deleted!" << endl;
}
else{
cout << "Medicine not Found!" << endl;
}
}
}
void mList::countMedicine(){
int count = 0;
mNode *temp = head;
while (temp != NULL){
count++;
temp = temp->next;
}
cout << "\tNumber of Medicine(s) in the "
<< "List is " << count << endl;
delete temp;
}
void displayNote(){
cout << "Note : You can only Add 3 types of Medicines." << endl;
cout << "\t1.Liquid\n\t2.Tablet\n\t3.Capsules\n";
cout << "\tYour Choice : ";
}
void displayMenu(){
cout << "\t\t\tMedical Store Managment!\n\n\n";
cout << "\t1.To ADD new Medicine." << endl;
cout << "\t2.To REMOVE Medicine." << endl;
cout << "\t3.To FIND Medicine by Name." << endl;
cout << "\t4.To SHOW Medicines of same Type." << endl;
cout << "\t5.To DISPLAY all Medicines." << endl;
cout << "\t0. To EXIT. " << endl;
cout << "\tYour Choice : ";
}
void case0(){
cin.get();
if (newList.isEmpty()){
exit(0);
}
else{
char c;
cout << "\tDo you Want to save List for Later use? (y/n) : ";
cin >> c;
if (c == 'n' || c == 'N'){
fout.open("data.txt", ios::trunc);
fout.close();
}
if (c == 'y' || c == 'Y'){
fout.open("data.txt", ios:ut & ios::trunc);
if (!fout){
system("cls");
cout << "\tError Creating File!" << endl;
}
else{
newList.addTofile();
cout << "List Added to File!" << endl;
}
}
}
}
void case1(){
system("cls");
displayNote();
Medicine nM;
char c;
cin >> c;
if ((c < '1') || (c > '3')){
case1();
}
system("cls");
cout << "Enter Med's Name: ";
cin >> nM.name;
if (c == '1'){
nM.type = "Liquid";
}
if (c == '2')
nM.type = "Tablet";
if (c == '3')
nM.type = "Capsules";
if (c == '1'){
cout << "Enter Med's Quantity(ml) : ";
cin >> nM.weight;
}
else{
cout << "Enter Med's Weight(mg) : ";
cin >> nM.weight;
}
cout << "Enter Expiry Date (dd/mm/yyyy) : ";
cin >> nM.expiryDate;
cout << "Enter Med's Price : ";
cin >> nM.price;
newList.addMedicine(nM);
system("cls");
cout << "\tMedicine Added!";
Sleep(1000);
system("cls");
main();
}
void case2(){
system("cls");
if (newList.isEmpty()){
cout << "Empty List! Nothing to Remove." << endl;
}
else{
string name;
cout << "\tEnter Med's Name to Delete : ";
cin >> name;
newList.removeMedicine(name);
}
Sleep(2000);
system("cls");
main();
}
void case3(){
if (!newList.isEmpty()){
system("cls");
string name;
cout << "Enter Medicine Name to Find : ";
cin >> name;
newList.searchMedicine(name);
system("pause");
}
else{
system("cls");
cout << "\tEmpty List\n";
system("pause");
}
system("cls");
main();
}
void case4(){
system("cls");
if (newList.isEmpty()){
cout << "\tNo Medicines in the List!" << endl;
Sleep(2000);
}
else{
cout << "Note.Following Med's type could in the List\n";
cout << "\t1.Liquid\n\t2.Tablet\n\t3.Capsules\n";
cout << "\tYour Choice : "; char c;
cin >> c;
system("cls");
if (c <'1' || c > '3'){
case4();
}
if (c == '1')
newList.DisplayMed("Liquid");
if (c == '2')
newList.DisplayMed("Tablet");
if (c == '3')
newList.DisplayMed("Capsules");
system("pause");
}
system("cls");
main();
}
void case5(){
system("cls");
if (!newList.isEmpty()){
newList.countMedicine();
}
newList.showM_List();
system("pause");
system("cls");
main();
}
void caseD(){
system("cls");
system("color 4F");
cout << "\n\n\n\n\n\n\n\n\n\n\t\t\t\tInvalid Input!" << endl;
Sleep(2000);
system("color F0");
system("cls");
main();
}
void filecheck()
{
fin.open("data.txt", ios::in | ios::beg);
if (!fin.is_open())
{
cerr << "\tError Opening File!\n";
}
else
{
Medicine m;
string line;
while (getline(fin, line))
{
stringstream newL(line);
string s;
int c = 0;
while (getline(newL, s, ','))
{
if (c == 0)
{
m.name = s;
}
if (c == 1)
{
m.type = s;
}
if (c == 2)
{
m.weight = s;
}
if (c == 3)
{
m.expiryDate = s;
}
if (c == 4){
m.price = atof(s.c_str());
}
c++;
}
newList.addMedicine(m);
}
}
fin.close();
}
char c = '0';
int main()
{
system("color F0");
if (c == '0'){
filecheck();
c = '1';
}
char choice;
displayMenu();
cin >> choice;
switch (choice){
case '0':
case0();
break;
case '1':
case1();
break;
case '2':
case2();
break;
case '3':
case3();
break;
case '4':
case4();
break;
case '5':
case5();
break;
default:
caseD();
}
return 0;
}
Bookmarks