Getting to grips with Header and cpp files

Expanding on the Want Cake program I now have them structured into files. Along with more code added:

Showing the files and folders

Now the code is:

main cpp

#include <iostream>
#include <string>
#include <unistd.h>
#include <cstdlib>

#include "functions.h"


using namespace std;



int main()

{
  string cake, pieces, drink;
  cake:
  
  cake = get_cake();
  pieces = get_pieces();
  drink = get_drink();
  
  cout << " You ordered " << cake << " At " << pieces << " pieces of cake and a drink of " << drink << "\n";
  
  say_thankyou();
  
//System Command that won't be staying I only added this until I learn  an alternative 
  sleep (3); 
  std::system("clear");
  goto cake;
  
          
          return 0;
  
 
}

cake cpp

#include <iostream>
#include <string>
#include <unistd.h>
#include <cstdlib>


using namespace std;

std::string get_cake() {
  std::string cake;
  cout << "Hello and welcome to the cake shop - What type of cake do you want? ";
  getline (cin, cake);
  cout << cake << " Great Choice! \n";

  
  return cake;
}



void say_thankyou() {
 
  cout << "Thank you for shopping at The Cake Shop... Have a great day.... \n";
  cout << "Next customer please! \n";
  //sleep (3); 
}

Drink cpp

#include <cstdlib>
#include <iostream>

using namespace std;

std::string get_drink() {
  std::string drink;
  cout << "What drink do you want? ";
  getline (cin, drink);
  cout << "You now have a " << drink << " aswell\n";
  
  
  
  return drink;
  
  
}

pieces.cpp

#include <cstdlib>
#include <iostream>

using namespace std;
std::string get_pieces() {
  std::string pieces; 
  cout << "How many pieces of cake do you want? ";
  getline (cin, pieces);
  cout <<"You now have " << pieces << " Pieces of Cake .\n";
  
  return pieces;
}

functions.h

#ifndef FUNCTIONS_H
#define FUNCTIONS_H

#include <iostream>

std::string get_cake();
std::string get_pieces();
std::string get_drink();
void say_thankyou();

#endif /* FUNCTIONS_H */

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *