Consider the following steps to help organize your code design. Be sure to focus on their interactions as you work. Both C and Python will be necessary to successfully complete this criteria. Create code that prints a multiplication table for a given numeric value. 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. Any user input other than 1,2, or 3 should result in an error message that returns the user to the menu. The menu should be displayed using a loop, where the user can choose to exit the program only by selecting option 3. If either of the first two options are selected, then users need to be prompted to input a numeric value. It needs to include options for the display of a multiplication table, doubling a value, and exiting the program. Your simple program will need a menu that can validate user input and is easy to use. Use C to successfully complete this criterion. Specifically, you must address the following rubric criteria: - Design a menu with appropriate user interactions and checks for valid entry. Note that when you compile your code, you will be able to tell if semicolon, calling a function that does not exist, not closing an open bracket, or using double quotes and not closing them in a string, among others. As you work, continue checking your code's syntax to ensure your code will run. Understanding the starter code will help you effectively build off the C and Python components you have been given in order to complete the design of a simple math-based program. Be sure you have already reviewed the Module Six Assignment Video or its transcript, as they contain important information regarding what is included in the starter code. Next, add the code from the CS210 Starter CPP Code and CS210 Starter PY Code files in the appropriate tabs of your project. Remember you will be working in Release mode rather than Debug mode for this work because it includes Python. Prompt Begin by opening a Visual Studio project file that has correctly combined C and Python, which you already set up in a previous module. For this assignment, you will be taking time to practice working in two different languages while designing code that can complete some simple mathematical tasks in C and Python. Overview When this occurs, you will need to be able to understand the role each different language plays in the overall project and how they connect. printf("Result is %d\n", _PyLong_AsInt(presult)) Ĭout << callIntFunc("PrintMe","House") << endl Presult = PyObject_CallObject(pFunc, pValue) PFunc = PyDict_GetItemString(pDict, procname) PName = PyUnicode_FromString((char*)"PythonCode") PyObject *pName, *pModule, *pDict, *pFunc, *pValue = nullptr, *presult = nullptr Int callIntFunc(string proc, string param)Ĭhar *paramval = new char To call this function, pass the name of the Python functino you wish to call and the string parameter you want to send PyObject* my_result = PyObject_CallObject(my_function, NULL) PyObject* my_function = PyObject_GetAttrString(my_module, procname) PyObject* my_module = PyImport_ImportModule("PythonCode") Python will print on the screen: Hello from python!Ĭhar *procname = new char To call this function, simply pass the function name in Python that you wish to call. Hello, I need help with this program using C and
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |