Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Rewrite the program from the lesson by using C?strings instead of the C++ string

ID: 3901933 • Letter: R

Question

Rewrite the program from the lesson by using C?strings instead of the C++ string class. Do NOT 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 workorder. Requirements: 1. Main program a. Output instructions to the user to enter the work order in the appropriate format: i. First 5?6 digits represent the customer number followed by the letter w ii. The digits following the letter w represent the year iii. The remaining digits (up to 5) represent the order number b. Input the work order into a char array of size 20 c. Breakdown the work order by calling the functions described below d. Output the components of the work order i. Length ii. Location of the letter w iii. Customer number iv. Year v. Order number 2. Create and use the following functions to break out the components of the work order: a. Built?in function strlen (workOrder) i. Returns the length of the char array b. int findW (char[], int); i. Searches the workOrder to find the location of the letter w ii. Returns the array location of the letter w c. long getCustNum (char[], int); i. Transfers the characters in the work order prior to the letter w into a local customer number character array ii. Converts the local customer number character array to type long iii. Returns the long value of the customer number d. int getYear (char[], int); i. Returns the two digist following the letter w as type int e. long getOrderNum (char[], int, int); i. Transfers the characters in the work order following the letter w into a local char array ii. Converts the local char array to type long iii. Returns the long value f. Program must be documented with the following: Name, Date, Program Name, Description.

//Program from last lesson:

In the example below, the program below inputs the second column in order to extract the customer number, the year, and the order number. For example the first number 91800w940770 is broken into 3 parts: 91800 is the customer number, the w indicates a work order, the next two digits are the year and the remaining digits are the work order number. The customer number could be 5 to 6 digits and the work order could expand to 5 digits.

Depending on what library functions you want to use dictate the header you will use. The program above uses the string header. This allows you to use certain functions such as .assign. If you do not include the correct header, then the program will not compile.

Your assignment for this topic will be to rewrite the above program using the C-strings. You will find the instructions to the assignment in the appropriate drop box

#include using namespace std; //need this if working with string clas:s int main() int strLength, wPointer; string custNumber, year, workOrderNumber; string workOrder"91800w940770"; strLength- workorder.length); wPointer workOrder.find 'w',0); custNumber.assign (workOrder, 0, wPointer); year.assign(workOrder, wPointer + 1, 2); //the year is the two digits after the w workOrderNumber.assign(workOrder, wPointer 3, strLength); I/extracting the work order number //remember the first digit in the string is a 0 //extracting the customer number EAAAAA CIS 12021Topic 6New folderlstrings Debuglstrings.exe cout

Explanation / Answer

#include <iostream>
#include <cstring>
#include <cstdlib>
using namespace std;

int findW (char[], int);
long getCustNum (char[], int);
int getYear(char str[], int start);

int main()

{
  
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(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(cnum, str, wIndex);
return atol(cnum);
}

int getYear(char str[], int start)
{
char year[3];
strncpy(year, str + start, 2);
return atoi(year);
}

output
=====
The length is 12
The location of the w is 5
The customer nmber is 91800
The order number is 0770

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote