Write me a c++ script implementing the Tortellini's recipe
Assistant
Sure, I'd be happy to help you with that! Here's a C++ script that implements a recipe for Tortellini with a simple tomato sauce. This recipe assumes you have already prepared the tortellini pasta and are ready to cook it. Here's the code:
User
Please rewrite it using a struct for storing quantities for a single person
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
#include <iostream>
#include <string>
#include <vector>
// Function to display a step in the recipe
void displayStep(const std::string& step) {
std::cout << "Step: " << step << std::endl;
}
// Function to display a list of ingredients
void displayIngredients(const std::vector<std::string>& ingredients) {
std::cout << "Ingredients:" << std::endl;
for (const auto& ingredient : ingredients) {
std::cout << "- " << ingredient << std::endl;
}
}
// Function to cook the tortellini and tomato sauce
void cookTortellini() {
// Ingredients
std::vector<std::string> ingredients = {
"1 pound fresh tortellini pasta",
"2 tablespoons olive oil",
"1 small onion, finely chopped",
"2 cloves garlic, minced",
"1 can (14.5 ounces) diced tomatoes",
"1 can (8 ounces) tomato sauce",
"1 teaspoon dried basil",
"1 teaspoon dried oregano",
"Salt and pepper, to taste",
"Grated Parmesan cheese, for serving"
};
displayIngredients(ingredients);
// Steps
displayStep("1. Bring a large pot of salted water to a boil. Add the tortellini and cook according to package instructions.");
displayStep("2. While the tortellini is cooking, heat the olive oil in a large skillet over medium heat.");
displayStep("3. Add the onion and cook until softened, about 5 minutes.");
displayStep("4. Add the garlic and cook for an additional 1-2 minutes, until fragrant.");
displayStep("5. Add the diced tomatoes, tomato sauce, basil, oregano, salt, and pepper to the skillet. Stir to combine.");
displayStep("6. Bring the sauce to a simmer and cook for 10-15 minutes, until slightly thickened.");
displayStep("7. Drain the cooked tortellini and add it to the skillet with the sauce. Stir to combine.");
displayStep("8. Serve the tortellini hot, topped with grated Parmesan cheese.");
}
int main() {
cookTortellini();
return 0;
}
This script defines a function cookTortellini() that displays the ingredients and steps for cooking tortellini with a simple tomato sauce. The main() function calls cookTortellini() to display the recipe.
Certainly! Here's an updated version of the C++ script that uses a struct to store the quantities needed for a single person. This version also allows the user to input the number of people they want to serve, and it adjusts the ingredient quantities accordingly.
cpp
#include <iostream>
#include <string>
#include <vector>
#include <map>
// Struct to store quantities for a single person
struct PersonQuantities {
double tortellini;
std::string oliveOil;
std::string onion;
std::string garlic;
std::string dicedTomatoes;
std::string tomatoSauce;
std::string basil;
std::string oregano;
std::string parmesanCheese;
};
// Function to display a step in the recipe
void displayStep(const std::string& step) {
std::cout << "Step: " << step << std::endl;
}
// Function to display a list of ingredients with quantities
void displayIngredients(const std::map<std::string, PersonQuantities>& ingredients, int numPeople) {
std::cout << "Ingredients for " << numPeople << " people:" << std::endl;
for (const auto& ingredient : ingredients) {
std::cout << "- " << ingredient.first << ": ";
if (ingredient.second.tortellini > 0) {
std::cout << ingredient.second.tortellini * numPeople << " pounds of " << ingredient.first << std::endl;
} else {
std::cout << ingredient.second.oliveOil * numPeople << " tablespoons of " << ingredient.first << std::endl;
}
}
}
// Function to cook the tortellini and tomato sauce
void cookTortellini(int numPeople) {
// Quantities for a single person
PersonQuantities singlePersonQuantities = {
.tortellini = 1.0,
.oliveOil = "2 tablespoons",
.onion = "1 small",
.garlic = "2 cloves",
.dicedTomatoes = "1 can (14.5 ounces)",
.tomatoSauce = "1 can (8 ounces)",
.basil = "1 teaspoon",
.oregano = "1 teaspoon",
.parmesanCheese = "Grated, for serving"
};
// Ingredients with quantities for the given number of people
std::map<std::string, PersonQuantities> ingredients = {
{"Tortellini pasta", singlePersonQuantities},
{"Olive oil", singlePersonQuantities},
{"Onion", singlePersonQuantities},
{"Garlic", singlePersonQuantities},
{"Diced tomatoes", singlePersonQuantities},
{"Tomato sauce", singlePersonQuantities},
{"Dried basil", singlePersonQuantities},
{"Dried oregano", singlePersonQuantities},
{"Parmesan cheese", singlePersonQuantities}
};
displayIngredients(ingredients, numPeople);
// Steps
displayStep("1. Bring a large pot of salted water to a boil. Add " + std::to_string(singlePersonQuantities.tortellini * numPeople) + " pounds of tortellini and cook according to package instructions.");
displayStep("2. While the tortellini is cooking, heat " + std::to_string(singlePersonQuantities.oliveOil * numPeople) + " tablespoons of olive oil in a large skillet over medium heat.");
displayStep("3. Add " + singlePersonQuantities.onion + " and cook until softened, about 5 minutes.");
displayStep("4. Add " + singlePersonQuantities.garlic + " and cook for an additional 1-2 minutes, until fragrant.");
displayStep("5. Add " + singlePersonQuantities.dicedTomatoes + ", " + singlePersonQuantities.tomatoSauce + ", " + singlePersonQuantities.basil + ", " + singlePersonQuantities.oregano + ", salt, and pepper to the skillet. Stir to combine.");
displayStep("6. Bring the sauce to a simmer and cook for 10-15 minutes, until slightly thickened.");
displayStep("7. Drain the cooked tortellini and add it to the skillet with the sauce. Stir to combine.");
displayStep("8. Serve the tortellini hot, topped with grated " + singlePersonQuantities.parmesanCheese + ".");
}
int main() {
int numPeople;
std::cout << "Enter the number of people you want to serve: ";
std::cin >> numPeople;
cookTortellini(numPeople);
return 0;
}
In this updated version, the PersonQuantities struct stores the quantities needed for a single person. The displayIngredients() function now takes a map of ingredients with their respective quantities for the given number of people. The cookTortellini() function now accepts the number of people as an argument and adjusts the ingredient quantities accordingly. The main() function prompts the user to enter the number of people they want to serve and calls cookTortellini() with that number.