×
Samples Blogs Make Payment About Us Reviews 4.9/5 Order Now

Efficient Order Processing with Procedural Programming in C++ for R

June 02, 2024
Emily Jason
Emily Jason
🇬🇧 United Kingdom
C++
Emily Jason, an accomplished Programming Specialist with over 10 years of expertise, holds a Master's degree from a reputable academic institution.
Key Topics
  • How to Do Procedural Programming in C++ to Process Orders for R
  • What is this assignment about?

Claim Your Discount Today

Ring in Christmas and New Year with a special treat from www.programminghomeworkhelp.com! Get 15% off on all programming assignments when you use the code PHHCNY15 for expert assistance. Don’t miss this festive offer—available for a limited time. Start your New Year with academic success and savings. Act now and save!

Celebrate the Festive Season with 15% Off on All Programming Assignments!
Use Code PHHCNY15

We Accept

Tip of the day
Start with basic image processing concepts like color spaces and transformations. Practice simple OpenCV examples to build confidence before tackling complex tasks.
News
In 2024, the release of the 'AsyncIO Toolkit' has made asynchronous programming in Python more efficient. Similarly, 'React Quantum' introduces quantum computing concepts to JavaScript, expanding learning opportunities for students.

How to Do Procedural Programming in C++ to Process Orders for R

Below is a guideline for procedural programming in C++ to process orders for r. We will show you how to develop the program and the different blocks involved.

What is this assignment about?

This C++ homework will show you the procedure of creating a programme that processes clients’ orders for robots from the robots construction business. We will direct you on how to put together the different pieces of the robot, debugging process, the correct file structures for the customer details, and the file’s organization scheme. We also indicate the different header files involved in the program.

This is the header file of our program. The term "header file" refers to a file with the extension ".h" that contains shared C function declarations and macro definitions. There are two different kinds of header files: those created by the programmer and those provided by our compiler. As with the inclusion of the stdio.h header file, which is included with our compiler, we ask permission to use a header file by including it with the C pre-processing directive #include.
Including a header file is equivalent to duplicating its contents, but we avoid doing this because it will increase the likelihood of errors and is not a good idea to copy header file material into source files, especially if there are numerous source files in a programme.
Maintaining all constants, macros, system-wide global variables, and function prototypes in header files and including them wherever necessary is a straightforward approach in C or C++ systems.
/*
;* Robotics.h
;*
;* Created on: Aug 26, 2022
;* Author: thanh
;*/
#include
#include
using namespace std;
#ifndef ROBOTICS_H_
#define ROBOTICS_H_
// DEFINE some CONSTANT
#define DELIMETER ':'
#define CHAR_END_LINE '.'
// Define class to store the data structure
The C preprocessor is instructed to scan the specified file as input before moving on to the rest of the current source file using the #include directive. The output from the preprocessor is composed of the output that has previously been produced, the output from the included file, the output from the text following the #include directive, and finally the output.
The below block is the structure declaration part in which integer value has been declared (minimum and maximum) and a string
struct PART
{
; ; ; ; char part_code;
; ; ; ; string part_name;
; ; ; ; int minimum;
; ; ; ; int maximum;
; ; ; ; int complexity;
; ; ; ; PART(char c = ' ', string name = "", int min = 0, int max = 0, int comp = 0) {
; ; ; ; ; ; part_code = c;
; ; ; ; ; ; part_name = name;
; ; ; ; ; ; minimum = min;
; ; ; ; ; ; maximum = max;
; ; ; ; ; ; complexity = comp;
; ; ; ; }
};
The below block is for the initialization of the above declared structure. Cust name, prio name and string p is initialized here.
struct CUSTOMER
{
; ; ; ; string cust_name;
; ; ; ; string proj_name;
; ; ; p; string list_of_part;
; ; ; ; CUSTOMER(string cust, string proj, string p) {
; ; ; ; ; ; cust_name = cust;
; ; ; ; ; ; proj_name = proj;
; ; ; ; ; ; list_of_part = p;
; ; ; ; }
};
struct BUILDER
{
; ; ; ; string name;
; ; ; ; int ability;
; ; ; ; int variability;
; ; ; ; BUILDER(string n, int a, int v) {
; ; ; ; ; ; name = n;
; ; ; ; ; ; ability = a;
; ; ; ; ; ; variability = v;
; ; ; ; }
};
// Prototype for functional
vectorparsingPartsData(string);
vectorparsingCustomerData(string);
vectorparsingBuilderData(string);
void buildingRobot(BUILDER, CUSTOMER, vector, ofstream&);
int calculateRobotComplexity(vector, string);
int calculateRobotVariablity(int, string);
#endif /* ROBOTICS_H_ */
This form is used for system header files. It searches for a file named 'file' in a standard list of system directories. You can prepend directories to this list with the -I option while compiling your source code.
The main goal is to develop a programme that carries out the processing of client orders for robots from a robot construction business: ITR (Illawarra Toy Robotics). Customers' orders are used as the basis for the company's robot construction. Each robot is somewhat sophisticated, as would be expected, and will be put together only from pieces kept in the company's inventory. ITR technicians, often known as builders, have a variety of skills. Each builder's ability varies around a fixed value and has an impact on whether or not a robot is successfully built.
/*
;* Robotics.cpp
;*
;* Created on: Aug 26, 2022
;* Author: thanh
;*/
#include
#include
#include
#include
#include
#include
#include "Robotics.h"
using namespace std;
vectorparsingPartsData(string file_name)
{
; ; // A:Head:1:2:15
; ; vectorpart_data;
; ; ifstream input(file_name);
; ; if (input.is_open())
; ; {
; ; ; ; string line;
; ; ; ; while (getline(input, line))
; ; ; ; {
; ; ; ; ; ; stringstream ss(line);
; ; ; ; ; ; if (ss.good())
; ; ; ; ; ; {
; ; ; ; ; ; ; ; string codeStr, nameStr, minStr, maxStr, compStr;
; ; ; ; ; ; ; ; getline(ss, codeStr, DELIMETER);
; ; ; ; ; ; ; ; getline(ss, nameStr, DELIMETER);
; ; ; ; ; ; ; ; getline(ss, minStr, DELIMETER);
; ; ; ; ; ; ; ; getline(ss, maxStr, DELIMETER);
; ; ; ; ; ; ; ; getline(ss, compStr, CHAR_END_LINE);
; ; ; ; ; ; ; ; part_data.push_back(PART(codeStr[0], nameStr, atoi(minStr.c_str()), atoi(maxStr.c_str()), atoi(compStr.c_str())));
; ; ; ; ; ; }
The program continues to take input in the form od data of the customers who want to place order for the robots. It is done by debugging. The program started with the library functions used in cpp. Then we have to connect the code with the header file to run the program without any errors. In the other lines the user continues to take inputs for the customer data.
; ; }
; ; ; ; input.close();
; ; }
// cout << "DEBUG: PARTS DATABASE" << endl;
// for (size_t i = 0; i < part_data.size(); i++)
// {
// cout << "\t" << part_data[i].part_code << " : " << part_data[i].part_name << " : " << part_data[i].minimum << " : "
// << part_data[i].maximum << " : " << part_data[i].complexity << endl;
// }
; ; return part_data;
}
vectorparsingCustomerData(string file_name)
{
; ; // Dodgy Dan:Dog:BCACECC.
; ; vectorcustomer_data;
; ; ifstream input(file_name);
; ; if (input.is_open())
; ; {
; ; ; ; string line;
; ; ; ; while (getline(input, line))
; ; ; ; {
; ; ; ; ; ; stringstream ss(line);
; ; ; ; ; ; if (ss.good())
; ; ; ; ; ; {
; ; ; ; ; ; ; ; string custStr, projStr, listStr;
; ; ; ; ; ; ; ; getline(ss, custStr, DELIMETER);
; ; ; ; ; ; ; ; getline(ss, projStr, DELIMETER);
; ; ; ; ; ; ; ; getline(ss, listStr, CHAR_END_LINE);
; ; ; ; ; ; ; ; customer_data.push_back(CUSTOMER(custStr, projStr, listStr));
; ; ; ; ; ; }
; ; ; ; }
; ; ; ; input.close();
; ; }
// cout << "DEBUG: CUSTOMER DATABASE" << endl;
// for (size_t i = 0; i < customer_data.size(); i++)
// {
// cout << "\t" << customer_data[i].cust_name << " : " << customer_data[i].proj_name << " : " << customer_data[i].list_of_part << endl;
// }
; ; return customer_data;
}
vectorparsingBuilderData(string file_name)
{
; ; // Reliable Rover:70:1.
; ; vectorbuilders_data;
; ; ifstream input(file_name);
; ; if (input.is_open())
; ; {
; ; ; ; string line;
; ; ; ; while (getline(input, line))
; ; ; ; {
; ; ; ; ; ; stringstream ss(line);
; ; ; ; ; ; if (ss.good())
; ; ; ; ; ; {
; ; ; ; ; ; ; ; string nameStr, abiStr, varStr;
; ; ; ; ; ; ; ; getline(ss, nameStr, DELIMETER);
; ; ; ; ; p; ; ; getline(ss, abiStr, DELIMETER);
; ; ; ; ; ; ; ; getline(ss, varStr, CHAR_END_LINE);
; ; ; ; ; ; ; ; builders_data.push_back(BUILDER(nameStr, atoi(abiStr.c_str()), atoi(varStr.c_str())));
; ; ; ; ; ; }
; ; ; ; }
; ; ; ; input.close();
; ; }
// cout << "DEBUG: BUILDER DATABASE" << endl;
// for (size_t i = 0; i < builders_data.size(); i++)
// {
// cout << "\t" << builders_data[i].name << " : " << builders_data[i].ability << " : " << builders_data[i].variability << endl;
// }
; ; return builders_data;
}
Finding the program and try to build the robot for tree time. We have to keep in mind the complexity as well.
There are no more than 10 entries in the file Customers.txt, which houses the customer data. The name of the customer, the title of the project, and the parts needed to complete the order are all disclosed. The file's structure is as follows (fields are separated by colons, and lines are ended by full stops).
void buildingRobot(BUILDER builder, CUSTOMER customer, vectorparts, ofstream &out)
{
; ; int complexity = calculateRobotComplexity(parts, customer.list_of_part);
; ; int variablity = calculateRobotVariablity(builder.variability, customer.list_of_part);
; ; out << "Overall robot complexity = " << complexity << endl;
; ; out << "Overall robot variability = " << variablity << endl;
; ; // Now try to build the robot for tree time.
; int cnt = 0;
; ; while (cnt < 3)
; ; {
; ; ; ; switch (cnt)
; ; ; ; {
; ; ; ; ; ; case 1:
; ; ; ; ; ; ; out << "Attempting the build second times" << endl;
; ; ; ; ; ; ; ; break;
; ; ; ; ; ; case 2:
; ; ; ; ; ; ; ; out << "Attempting the build third times" << endl;
; ; ; ; ; ; ; ; break;
; ; ; ; ; ; default:
; ; ; ; ; ; ; ; break;
; ; ; ; }
The name of the person who placed the order is listed as the Customer. It is a printable string of non-empty characters that might contain white space.
The buyer selects the project name, which is meant to indicate the kind of robot that will be constructed. It is a non-empty string of printable characters that may include spaces, just like the Customer name is.
Each letter on the List of Parts's list of letters corresponds to a part in the Parts File. They don't have to be listed alphabetically. For any order, there shouldn't be more than 10 components.
; ; ; ; default_random_engine randEngine(rand());
; ; ; ; normal_distributionnormal(builder.ability, variablity);
; ; ; ; int randValue = normal(randEngine);
; ; ; ; out << "Normal random value: " << randValue << endl;
; ; ; if ((randValue + (cnt * 10)) >= complexity)
; ; ; ; {
; ; ; ; ; ; out << "Build successful" << endl;
; ; ; ; ; ; break;
; ; ; ; }
; ; ; ; else
; ; ; ; {
; ; ; ; ; ; out << "Build failed" << endl;
; ; ; ; ; ; cnt++;
; ; ; ; }
; ; }
}
int calculateRobotComplexity(vectorparts, string robot_parts)
{
; ; ;Determine the overall robot complexity as 22 plus the sum of the part complexities. For example,
; ; ;given a customer Sally the robot complexity is computed as:
; ; int complex_total = 0;
; ; for (size_t i = 0; i < robot_parts.size(); i++)
; ; {
; ; ; ; PART part_found;
; ; ; ; for (size_t p = 0; p < parts.size(); p++)
; ; ; ; {
; ; ; ; ; ; if (parts[p].part_code == robot_parts[i])
; ; ; ; ; ; {
; ; ; ; ; ; ; ; part_found = parts[p];
; ; ; ; ; ; ; ; break;
; ; ; ; ; ; }
; ; ; ; }
; ; ; ; complex_total += part_found.complexity;
; ; }
; ; if (complex_total + 22 > 100)
; ; ; ; return 100;
; ; return complex_total + 22;
}
int calculateRobotVariablity(int var, string robot_parts)
{
; ; Determine the overall robot variability as 4 plus the number of parts plus the variability of the builder.
; ; // j o h n n y t u o t - g m a i l
; ; return 4 + robot_parts.length() + var;
}
Builders.txt, a file that could have at least one entry and contain information about the potential builders the business could assign to complete an order, is one possible name for this file. Following is the file's organisational scheme (fields are separated by colons, and lines are concluded with full stops):
No empty name will do. The attribute has an inclusive integer value between 1 and 99. A builder's skill may vary around the value given in the record because the variability is an integer with a range of 1 to 10 inclusive.
/*
;* ITR.cpp
;*
;* Created on: Aug 26, 2022
;* Author: thanh
;*/
#include
#include
#include
#include
#include
#include "Robotics.h"
using namespace std;
int main(int argc, char **argv)
{
; ; if (argc != 5)
; ; {
; ; ; ; cout << "Usage: " << argv[0] << " " << endl;
; ; ; ; return 1;
; ; }
; ; vectorpart_data = parsingPartsData(argv[2]);
; ; vectorcust_data = parsingCustomerData(argv[1]);
; ; vectorbuilder_data = parsingBuilderData(argv[3]);
; ; string output_name = argv[4];
; ; ofstream output_file;
; ; output_file.open(output_name);
; ; if (output_file.is_open())
; ; {
; ; ; ; for (size_t i = 0; i < cust_data.size(); i++)
; ; ; ; {
; ; ; ; ; ; random_device device;
; ; ; ; ; ; mt19937 gen(device());
; ; ; ; ; ; uniform_int_distribution<> uniform(0, 2);
; ; ; ; ; int randValue = uniform(gen);
; ; ; ; ; ; output_file << "Processing customer : " << cust_data[i].cust_name << endl;
; ; ; ; ; ; output_file << "Order: " << cust_data[i].proj_name << endl;
; ; ; ; ; ; output_file << "Builder: " << builder_data[randValue].name << endl;
; ; ; ; ; ; buildingRobot(builder_data[randValue], cust_data[i], part_data, output_file);
; ; ; ; ; ; output_file << endl;
; ; ; ; }
; ; ; ; output_file.close();
; ; }
; ; return 0;
}

Similar Blogs