The answer needs both a C++ and a Python code and the source code for the C++ is a picture attached Design a menu with appropriate user interactions and checks for valid entry. Use C++ to successfully complete this criterion. Your simple program will need a menu that can validate user input and is easy to use. It needs to include options for the display of a multiplication table, doubling a value, and exiting the program. If either of the first two options are selected, then users need to be prompted to input a numeric value. The menu should be displayed using a loop, where the user can choose to exit the program only by selecting option 3. Any user input other than 1, 2, or 3 should result in an error message that returns the user to the menu. An example menu might look like the following:1: Display a Multiplication Table 2: Double a Value 3: Exit Enter your selection as a number 1, 2, or 3. Create code that prints a multiplication table for a given numeric value. Both C++ and Python will be necessary to successfully complete this criteria. Be sure to focus on their interactions as you work. Consider the following steps to help organize your code design. Note that you should have already written C++ code that prompts a user to input a number while working on the menu portion of this assignment. Write C++ code that reads and passes a number, as an integer, to Python. C++ should also call a function in Python to display the multiplication table for the passed parameter. Note that you will be creating that function in the next step. For this step, be sure to check the starter code you were given and use the applicable components. Write Python code to create a multiplication table for the given integer. Name this function MultiplicationTable for consistency. The printed table should include values for the multipliers one through ten. An example result is shown below. 6 X 1 = 6 6 X 2 = 12 6 X 3 = 18 6 X 4 = 24 6 X 5 = 30 6 X 6 = 36 6 X 7 = 42 6 X 8 = 48 6 X 9 = 54 6 X 10 = 60 Create code that doubles a given numeric value. Both C++ and Python will be necessary to successfully complete this criteria. Be sure to focus on their interactions as you work. Consider the following steps to help organize your code design. Note that you should have already written C++ code that prompts a user to input a number while working on the menu portion of this assignment. Once the number has been read from the user in C++, call the callIntFunc function. Then pass the Python function name (which you will create in the next step) and the value entered by the user as parameters to the callIntFunc function. Write a Python function to receive the user input and then return that value multiplied by two. For consistency, name the function you create DoubleValue. Refer to the example in your starter code as you work, but remember the example is squaring the value (or multiplying the value by itself) rather than doubling it. In C++, receive the value sent from the Python function (DoubleValue) and display the value on the screen. Apply industry standard best practices such as in-line comments and appropriate naming conventions to enhance readability and maintainability. Remember that you must demonstrate industry standard best practices in all your code to ensure clarity, consistency, and efficiency. This includes the following: Inputting validation and error handling to anticipate, detect, and respond to run-time and user errors (for example, make sure you have option 3 on your menu so users can exit the program) Inserting in-line comments to denote your changes and briefly describe the functionality of the code Using appropriate variable, parameter, and other naming conventions throughout your cod

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

The answer needs both a C++ and a Python code and the source code for the C++ is a picture attached

  • Design a menu with appropriate user interactions and checks for valid entry. Use C++ to successfully complete this criterion. Your simple program will need a menu that can validate user input and is easy to use. It needs to include options for the display of a multiplication table, doubling a value, and exiting the program. If either of the first two options are selected, then users need to be prompted to input a numeric value. The menu should be displayed using a loop, where the user can choose to exit the program only by selecting option 3. Any user input other than 1, 2, or 3 should result in an error message that returns the user to the menu. An example menu might look like the following:1: Display a Multiplication Table 2: Double a Value 3: Exit Enter your selection as a number 1, 2, or 3.
  • Create code that prints a multiplication table for a given numeric value. Both C++ and Python will be necessary to successfully complete this criteria. Be sure to focus on their interactions as you work. Consider the following steps to help organize your code design. Note that you should have already written C++ code that prompts a user to input a number while working on the menu portion of this assignment.
    • Write C++ code that reads and passes a number, as an integer, to Python. C++ should also call a function in Python to display the multiplication table for the passed parameter. Note that you will be creating that function in the next step. For this step, be sure to check the starter code you were given and use the applicable components.
    • Write Python code to create a multiplication table for the given integer. Name this function MultiplicationTable for consistency. The printed table should include values for the multipliers one through ten. An example result is shown below.

6 X 1 = 6 6 X 2 = 12 6 X 3 = 18 6 X 4 = 24 6 X 5 = 30 6 X 6 = 36 6 X 7 = 42 6 X 8 = 48 6 X 9 = 54 6 X 10 = 60

  • Create code that doubles a given numeric value. Both C++ and Python will be necessary to successfully complete this criteria. Be sure to focus on their interactions as you work. Consider the following steps to help organize your code design. Note that you should have already written C++ code that prompts a user to input a number while working on the menu portion of this assignment.
    • Once the number has been read from the user in C++, call the callIntFunc function. Then pass the Python function name (which you will create in the next step) and the value entered by the user as parameters to the callIntFunc function.
    • Write a Python function to receive the user input and then return that value multiplied by two. For consistency, name the function you create DoubleValue. Refer to the example in your starter code as you work, but remember the example is squaring the value (or multiplying the value by itself) rather than doubling it.
    • In C++, receive the value sent from the Python function (DoubleValue) and display the value on the screen.
  • Apply industry standard best practices such as in-line comments and appropriate naming conventions to enhance readability and maintainability. Remember that you must demonstrate industry standard best practices in all your code to ensure clarity, consistency, and efficiency. This includes the following:
    • Inputting validation and error handling to anticipate, detect, and respond to run-time and user errors (for example, make sure you have option 3 on your menu so users can exit the program)
    • Inserting in-line comments to denote your changes and briefly describe the functionality of the code
    • Using appropriate variable, parameter, and other naming conventions throughout your code
O https://learn.snhu.edu/content/e x
O https://learn.snhu.edu/content/enforced/895821-CS-210-T2589-OL-TRAD-UG.21E..
#include <Python.h>
#include <iostream>
#include <windows.h>
#include <cmath>
#include <string>
using namespace std;
/*
Description:
To call this function, simply pass the function name in Python that you wish to call.
Example:
callProcedure("printsomething");
Output:
Python will print on the screen: Hello from python!
Return:
None
*/
void CallProcedure(string pName)
{
char *procname = new char[pName.length() + 1];
std::strcpy(procname, pName.c_str());
Py_Initialize();
Pyobject* my_module = PyImport_ImportModule("PythonCode");
PyErr_Print();
Pyobject* my_function = Pyobject_GetAttrString (my_module, procname);
Pyobject* my_result = Pyobject_Callobject (my_function, NULL);
Py_Finalize();
delete[] procname;
}
/*
Description:
To call this function, pass the name of the Python functino you wish to call and the string parameter you want to send
Example:
int x = callIntFunc ("PrintMe","Test");
Output:
Python will print on the screen:
You sent me: Test
Return:
100 is returned to the C++
*/
int callIntFunc (string proc, string param)
{
char *procname = new char[proc.length() + 1];
std::strcpy(procname, proc.c_str());
char *paramval = new char[param.length() + 1];
std::strcpy(paramval, param.c_str());
Pyobject *pName, *pModule, *pDict, *pFunc, *pValue = nullptr, *presult = nullptr;
// Initialize the Python Interpreter
Py_Initialize();
/ Build the name object
pName = PyUnicode_FromString((char*)"PythonCode");
// Load the module object
pModule - PyImport_Import(pName);
// pDict is
pDict = PyModule_GetDict (pModule);
// pFunc is also a borrowed reference
pFunc = PyDict_GetItemString(pDict, procname);
if (PyCallable_Check(pFunc))
{
borrowed reference
pvalue = Py_BuildValue("(z)", paramval);
PyErr_Print();
presult = Pyobject_Callobject(pFunc, pValue);
PyErr_Print();
else
{
PyErr_Print();
}
//printf("Result is %d\n", _PyLong_AsInt(presult));
Py_DECREF (pValue);
// Clean up
Py_DECREF (pModule);
Py_DECREF (pName);
// Finish the Python Interpreter
Py_Finalize();
// clean
delete[] procname;
delete[] paramval;
return _PyLong_AsInt (presult);
}
Description:
To call this function, pass the name of the Python functino you wish to call and the string parameter you want to send
Example:
int x = callIntFunc ("doublevalue",5);
Return:
25 is returned to the C++
*/
int callIntFunc (string proc, int param)
{
char *procname = new char[proc.length() + 1];
std::strcpy(procname, proc.c_str());
Pyobject *pName, *pModule, *pDict, *pFunc, *pValue = nullptr, *presult = nullptr;
// Initialize the Python Interpreter
Py_Initialize();
// Build the name
pName = PyUnicode_FromString((char*)"PythonCode");
// Load the module object
pModule = PyImport_Import(pName);
// pDict is a borrowed reference
pDict = PyModule_GetDict (pModule);
// pFunc is also a borrowed reference
PyDict_GetItemString(pDict, procname);
pFunc
if (PyCallable_Check(pFunc))
{
pValue = Py_Buildvalue("(i)", param);
PyErr_Print();
presult = Pyobject_Callobject(pFunc, pValue);
PyErr_Print();
}
else
{
PyErr_Print();
}
//printf("Result is %d\n", _PyLong_AsInt (presult));
Py_DECREF (pValue);
i Clean up
Py_DECREF (pModule);
Py_DECREF (pName);
// Finish the Python Interpreter
Py_Finalize();
// clean
delete[] procname;
return _PyLong_AsInt (presult);
}
void main()
{
CallProcedure("printsomething");
cout <« callIntFunc ("PrintMe", "House") « endl;
cout « callIntFunc ("SquareValue", 2);
}
Transcribed Image Text:O https://learn.snhu.edu/content/e x O https://learn.snhu.edu/content/enforced/895821-CS-210-T2589-OL-TRAD-UG.21E.. #include <Python.h> #include <iostream> #include <windows.h> #include <cmath> #include <string> using namespace std; /* Description: To call this function, simply pass the function name in Python that you wish to call. Example: callProcedure("printsomething"); Output: Python will print on the screen: Hello from python! Return: None */ void CallProcedure(string pName) { char *procname = new char[pName.length() + 1]; std::strcpy(procname, pName.c_str()); Py_Initialize(); Pyobject* my_module = PyImport_ImportModule("PythonCode"); PyErr_Print(); Pyobject* my_function = Pyobject_GetAttrString (my_module, procname); Pyobject* my_result = Pyobject_Callobject (my_function, NULL); Py_Finalize(); delete[] procname; } /* Description: To call this function, pass the name of the Python functino you wish to call and the string parameter you want to send Example: int x = callIntFunc ("PrintMe","Test"); Output: Python will print on the screen: You sent me: Test Return: 100 is returned to the C++ */ int callIntFunc (string proc, string param) { char *procname = new char[proc.length() + 1]; std::strcpy(procname, proc.c_str()); char *paramval = new char[param.length() + 1]; std::strcpy(paramval, param.c_str()); Pyobject *pName, *pModule, *pDict, *pFunc, *pValue = nullptr, *presult = nullptr; // Initialize the Python Interpreter Py_Initialize(); / Build the name object pName = PyUnicode_FromString((char*)"PythonCode"); // Load the module object pModule - PyImport_Import(pName); // pDict is pDict = PyModule_GetDict (pModule); // pFunc is also a borrowed reference pFunc = PyDict_GetItemString(pDict, procname); if (PyCallable_Check(pFunc)) { borrowed reference pvalue = Py_BuildValue("(z)", paramval); PyErr_Print(); presult = Pyobject_Callobject(pFunc, pValue); PyErr_Print(); else { PyErr_Print(); } //printf("Result is %d\n", _PyLong_AsInt(presult)); Py_DECREF (pValue); // Clean up Py_DECREF (pModule); Py_DECREF (pName); // Finish the Python Interpreter Py_Finalize(); // clean delete[] procname; delete[] paramval; return _PyLong_AsInt (presult); } Description: To call this function, pass the name of the Python functino you wish to call and the string parameter you want to send Example: int x = callIntFunc ("doublevalue",5); Return: 25 is returned to the C++ */ int callIntFunc (string proc, int param) { char *procname = new char[proc.length() + 1]; std::strcpy(procname, proc.c_str()); Pyobject *pName, *pModule, *pDict, *pFunc, *pValue = nullptr, *presult = nullptr; // Initialize the Python Interpreter Py_Initialize(); // Build the name pName = PyUnicode_FromString((char*)"PythonCode"); // Load the module object pModule = PyImport_Import(pName); // pDict is a borrowed reference pDict = PyModule_GetDict (pModule); // pFunc is also a borrowed reference PyDict_GetItemString(pDict, procname); pFunc if (PyCallable_Check(pFunc)) { pValue = Py_Buildvalue("(i)", param); PyErr_Print(); presult = Pyobject_Callobject(pFunc, pValue); PyErr_Print(); } else { PyErr_Print(); } //printf("Result is %d\n", _PyLong_AsInt (presult)); Py_DECREF (pValue); i Clean up Py_DECREF (pModule); Py_DECREF (pName); // Finish the Python Interpreter Py_Finalize(); // clean delete[] procname; return _PyLong_AsInt (presult); } void main() { CallProcedure("printsomething"); cout <« callIntFunc ("PrintMe", "House") « endl; cout « callIntFunc ("SquareValue", 2); }
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Structure chart
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
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education