Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Lab Assignment 2 In this lab assignment, you will design three global functions that work with low-level arrays and use pointers. When solving this assignment,
Lab Assignment 2 In this lab assignment, you will design three global functions that work with low-level arrays and use pointers. When solving this assignment, consider the following quote attributed to David J. Wheeler, Bjarne Stroustrup's PhD advisior: Any problem in computer science can be solved with another layer ofindirection, except of course for the problem of too many indirections. 1. Create a source and a header file for the functions and name them double_array.cpp and double_array.h, respectively. We will also need amain.cpp. Make sure to use the names exactly as typed, otherwise the TAs may return the files to you. 2. In your main routine, define the following local arrays of size 10, a double array named dArray, a character array named cArray and an array to hold 10 old-style C-strings (more details below). Set the values stored in dArray to random floating numbers between -1000.0 and +1000.0. For this assignment the basic pseudo-random number generator from the C-library is good enough, i.e., you can use the following #inc luce srand (42); double rVal-1000.0 2000.0 * static_cast (rand)) /static_cast (RAND MAX); 3. Define a function printArray returning void and accepting as parameter a pointer to the first element of a double array. If you find that you need an extra parameter, you can add it 4. Define a function double2Char returning bool and accepting as one parameter a pointer to the first element of a double array as the source and another parameter a pointer to the first element of a char array as the destination. If you find that you need an extra parameter, you can add it. Inside double2Char, you can further assume that the character array is large enough to hold the result (as you have properly created it large enough in main). The function should convert an entry in the double array to a char by clipping it to the minimum and maximum value of char and truncating it to an integer value. Example: 115.7862 should be converted to 115. Your function should return true on success 5. Define another function getcharacters returning bool and accepting as one parameter a pointer to the first element of a char array as the source and as another parameter a pointer to the first old-style C-string in an array of old style C-strings as the destination. If you find that you need an extra parameter, you can add it. The function is to convert the numbers in the character array to old-style C-strings. Note that you will need to make sure when creating the array of old-style C-strings in main that the old-style C-strings are large enough but no larger to accommodate the expected results, i.e., each old-style C-string should be long enough to hold the longest possible string. Inside getCharacters, you can assume that the destination old-style C-string array is large enough to hold the result (as you have properly created it large enough in main).Consider that an ASCII table sts the following: 0 maps to 30 hexadecimal or 48 decimal and 9 maps to 39 hexadecimal or 57 decimal. The minus sign is 2D hexadecimal and 45 decimal 6. Your main is to create all the arrays and then call the above functions one-by-one. In the end print the old-style C-strings as returned from getCharacters You must hand-in one archive exactly named: double_array.zip which should contain three files double_array.cpp, double_array.h and main.cpp. Do not hand in any other files or use any other orm of archive. No word files or pd s or sunilar word processing files will be acceptea and submitted will result m an automatic O
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