#include #include "VendingMachine.h" int main() {    /* Type your code here. */    return 0; } VendingMachine.h   #ifndef VENDING_MACHINE_H #define VENDING_MACHINE_H typedef struct VendingMachine_struct {

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter11: Advanced Inheritance Concepts
Section: Chapter Questions
Problem 8RQ
icon
Related questions
Question
100%

Implement in C Programming

7.7.1: LAB: Vending machine

main.c

 

#include <stdio.h>

#include "VendingMachine.h"

int main() {

   /* Type your code here. */

   return 0;
}

VendingMachine.h

 

#ifndef VENDING_MACHINE_H
#define VENDING_MACHINE_H

typedef struct VendingMachine_struct {
   int bottles;
} VendingMachine;

VendingMachine InitVendingMachine();
VendingMachine Purchase(int amount, VendingMachine vm);
VendingMachine Restock(int amount, VendingMachine vm);
int GetInventory(VendingMachine vm);
void Report(VendingMachine vm);

#endif

VendingMachine.c

 

#include <stdio.h>
#include <string.h>

#include "VendingMachine.h"

VendingMachine InitVendingMachine(){
   VendingMachine newVM;
   
   newVM.bottles = 20;
   
   return newVM;
}

VendingMachine Purchase(int amount, VendingMachine vm){
   vm.bottles = vm.bottles - amount;  
   
   return vm;
}

VendingMachine Restock(int amount, VendingMachine vm){
   vm.bottles = vm.bottles + amount;
   
   return vm;
}

int GetInventory(VendingMachine vm){
   return vm.bottles;
}

void Report(VendingMachine vm){
   printf("Inventory: %d bottles\n", vm.bottles);
}

 

Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Returning value from Function
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT