LEASE FIX THE CODE PROPERLY BELOW AND MAKE SURE IT WILL RUN PROPERLY ONLY USE C LANGUAGE BECAUSE ITS NOT RUNNING IN C COMPILER   #include #include #include #include typedef struct Date Date; struct Date{ int day, month, year;   void print() { cout << day << "-" << month << "-" << year << endl; } //Input data from the user };   Date _Date(int d = 1, int m = 1, int y = 2000) { day = d; month = m; year = y;   } void input() { int day,month,year; printf("Enter day:"); scanf("%d", &day); ; printf ("Enter month:"); scanf("%d", &month); printf( "Enter year:"); scanf("%d", &year); int getYear() { return year; } int getMonth() { return month; } int getDay() { return day; } }   // A medicine class is made struct Medicine { protected: int medID; int price; Date expiryDate; int quantityInStock; public: //Constructor Medicine() {} //Parametrized Constructor   }; Medicine _Medicine(int id, int p, Date e, int q) { medID = id; price = p; expiryDate = e; quantityInStock = q; } //Input medicine detail void input() {   printf(" Enter Medicine Id:\n"); scanf("%d", &medID); printf("Enter price of medicine:"); scanf("%d", &price); printf("Enter quantity in stock:\n"); scanf("%d", &quantityInStock); //expiryDate is an object of class Date so the input method of Date class is called using the object expiryDate expiryDate.input(); } //Display medicine record void display() { printf("Medicine ID: %d:" , medID ,"\n"); printf("Price: %d:", price, "\n"); printf("Quantity in Stock: %d:" ,quantityInStock,"\n"); printf("Expiry Date: %d:"); expiryDate.print(); printf( "---------- \n"); } void setquantity(int q) { quantityInStock = q; } void setID(int id) { medID = id; } int getID() { return medID; } int getquantity() { return quantityInStock; } static int countRecords() { ifstream f("medData.dat", ios::binary); f.seekg(0, ios::end); int loc = f.tellg(); return loc / sizeof(Medicine); } friend void saveMedicineData(Medicine m); friend void displayAllData(); void updateStock(int mID, int quantity) {   fstream f; http://f.open("medData.dat", ios::out | ios::in | ios::binary); int n = Medicine::countRecords(); //Read all records from file into an array Medicine* e = new Medicine[n]; for (int i = 0; i < n; i++) { http://f.read(reinterpret_cast(&e[i]), sizeof(Medicine)); if (mID == medID) { int newquantity = e[i].getquantity() - quantity; e[i].setquantity(newquantity); } } f.seekp(0);   f.write(reinterpret_cast(e), sizeof(Medicine) * n); f.close(); } void saveMedicineData(Medicine m) {   ofstream outFile; http://outFile.open("medData.dat", ios::binary | ios::app);   outFile.write(reinterpret_cast (&m), sizeof(Medicine)); outFile.close(); printf("\n\nMedicine record has been created successfully "); sin.ignore(); sin.get(); system("pause"); } void displayAllData() { Medicine me; ifstream inFile; http://inFile.open("medData.dat", ios::binary); if (!inFile) { printf( "File could not be open !! Press any Key..."); sin.ignore(); sin.get()in.ignore(); sin.get(); system("pause");   } }   int main() {//First object of medicine Medicine med; med.input(); med.display(); saveMedicineData(med); displayAllData();   //Updation   int medToSell; printf("Enter ID of medicine to sale \n"); scanf("%d", &medToSell); int quantitySold; printf("Enter the quantity to be sold\n"); scanf("%d", &quantitySold); printf("----------\n"); printf("Selling medicine: %d:",medToSell , " to a customer.\n"); printf("Quantity Sold: %d:" ,quantitySold ,"\n"); med.updateStock(medToSell, quantitySold); printf("----------\n" ); //See the updated list of medicines after sale printf("Updated Stock after sales:\n"); displayAllData();   printf( "---End---\n" )

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

PLEASE FIX THE CODE PROPERLY BELOW AND MAKE SURE IT WILL RUN PROPERLY ONLY USE C LANGUAGE BECAUSE ITS NOT RUNNING IN C COMPILER

 

#include <stdio.h>

#include<conio.h>

#include<string.h>

#include<math.h>

typedef struct Date Date;

struct Date{

int day, month, year;

 

void print() {

cout << day << "-" << month << "-" << year << endl;

}

//Input data from the user

};

 

Date _Date(int d = 1, int m = 1, int y = 2000) {

day = d;

month = m;

year = y;

 

}

void input() {

int day,month,year;

printf("Enter day:");

scanf("%d", &day); ;

printf ("Enter month:");

scanf("%d", &month);

printf( "Enter year:");

scanf("%d", &year);

int getYear() { return year; }

int getMonth() { return month; }

int getDay() { return day; }

}

 

// A medicine class is made

struct Medicine {

protected:

int medID;

int price;

Date expiryDate;

int quantityInStock;

public:

//Constructor

Medicine() {}

//Parametrized Constructor

 

};

Medicine _Medicine(int id, int p, Date e, int q) {

medID = id;

price = p;

expiryDate = e;

quantityInStock = q;

}

//Input medicine detail

void input()

{

 

printf(" Enter Medicine Id:\n");

scanf("%d", &medID);

printf("Enter price of medicine:");

scanf("%d", &price);

printf("Enter quantity in stock:\n");

scanf("%d", &quantityInStock);

//expiryDate is an object of class Date so the input method of Date class is called using the object expiryDate

expiryDate.input();

}

//Display medicine record

void display() {

printf("Medicine ID: %d:" , medID ,"\n");

printf("Price: %d:", price, "\n");

printf("Quantity in Stock: %d:" ,quantityInStock,"\n");

printf("Expiry Date: %d:");

expiryDate.print();

printf( "---------- \n");

}

void setquantity(int q) { quantityInStock = q; }

void setID(int id) { medID = id; }

int getID() { return medID; }

int getquantity() { return quantityInStock; }

static int countRecords() {

ifstream f("medData.dat", ios::binary);

f.seekg(0, ios::end);

int loc = f.tellg();

return loc / sizeof(Medicine);

}

friend void saveMedicineData(Medicine m);

friend void displayAllData();

void updateStock(int mID, int quantity) {

 

fstream f;

http://f.open("medData.dat", ios::out | ios::in | ios::binary);

int n = Medicine::countRecords();

//Read all records from file into an array

Medicine* e = new Medicine[n];

for (int i = 0; i < n; i++) {

http://f.read(reinterpret_cast<char*>(&e[i]), sizeof(Medicine));

if (mID == medID)

{

int newquantity = e[i].getquantity() - quantity;

e[i].setquantity(newquantity);

}

}

f.seekp(0);

 

f.write(reinterpret_cast<char*>(e), sizeof(Medicine) * n);

f.close();

}

void saveMedicineData(Medicine m)

{

 

ofstream outFile;

http://outFile.open("medData.dat", ios::binary | ios::app);

 

outFile.write(reinterpret_cast<char*> (&m), sizeof(Medicine));

outFile.close();

printf("\n\nMedicine record has been created successfully ");

sin.ignore();

sin.get();

system("pause");

}

void displayAllData()

{

Medicine me;

ifstream inFile;

http://inFile.open("medData.dat", ios::binary);

if (!inFile)

{

printf( "File could not be open !! Press any Key...");

sin.ignore();

sin.get()in.ignore();

sin.get();

system("pause");

 

}

}

 

int main()

{//First object of medicine

Medicine med;

med.input();

med.display();

saveMedicineData(med);

displayAllData();

 

//Updation

 

int medToSell;

printf("Enter ID of medicine to sale \n");

scanf("%d", &medToSell);

int quantitySold;

printf("Enter the quantity to be sold\n");

scanf("%d", &quantitySold);

printf("----------\n");

printf("Selling medicine: %d:",medToSell , " to a customer.\n");

printf("Quantity Sold: %d:" ,quantitySold ,"\n");

med.updateStock(medToSell, quantitySold);

printf("----------\n" );

//See the updated list of medicines after sale

printf("Updated Stock after sales:\n");

displayAllData();

 

printf( "---End---\n" );

 

}

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
ADT and Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-engineering and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY