Question
C++ Question for a homework assignment Rewrite the program from the lesson by using C-strings instead of the C++ string class. Do not use the
C++ Question for a homework assignment
Rewrite the program from the lesson by using C-strings instead of the C++ string class. Do not use the string header; use the cstring header instead. Create and use the functions described below to extract the length, location of 'w', year, customer number and order number from the work order. \\I've got this part working okay.
The user must also have the following text displayed as a prompt. \\This is where I'm stuck.
Enter a three part work order code in the format CustomerNumber Year OrderNumber
The first 5-6 digits contain the work order number < digits before the w
The 2 digits following the w represent the year
The remaining digits (up to 5) represent the work order number
Enter the work order code:
After the results display, it should show Press any key to continue... and then repeat the option. \\ Getting it to repeat I'm stuck.
Here is my code. I'm stuck at getting the text to display and then repeat the option after any key is pressed.
#include
#include
#include
using namespace std;
int findW(char[], int);
long getCustNum(char[], int);
int getYear(char str[], int start);
int main()
{
cout << Enter a three part work order code in the format CustomerNumber Year OrderNumber << endl;
cout << The first 5 - 6 digits contain the work order number cout << The 2 digits following the w represent the year << endl; cout << Enter work order code: << ; int strLength, wPointer; long custNumber; char workOrderNumber[6]; int year; char workOrder[] = "91800w940770"; strLength = strlen(workOrder); wPointer = findW(workOrder, strLength); custNumber = getCustNum(workOrder, wPointer); year = getYear(workOrder, wPointer + 1); strcpy_s(workOrderNumber, workOrder + wPointer + 3); cout << "The length is " << strLength << endl; cout << "The location of the w is " << wPointer << endl; cout << "The customer nmber is " << custNumber << endl; cout << "The order number is " << workOrderNumber << endl; system("pause"); return 0; } int findW(char str[], int len) { for (int i = 0; i < len; i++) { if (str[i] == 'w') return i; } return -1; } long getCustNum(char str[], int wIndex) { char cnum[7]; strncpy_s(cnum, str, wIndex); return atol(cnum); } int getYear(char str[], int start) { char year[3]; strncpy_s(year, str + start, 2); return atoi(year); }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started