Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Part 1 All code in Part 1 goes into one file called part1.c 1) Write a function that accepts two int pointers. The function should

image text in transcribedimage text in transcribedimage text in transcribed

Part 1 All code in Part 1 goes into one file called part1.c 1) Write a function that accepts two int pointers. The function should be named shiftLeft. There is no returrn value The first parameter is the address of the first element in an array of integers. Think of it as the address of array[O]. The second parameter is the address of the last element in the array. Think of it as array [size - 1]. The function should shift all of the elements one position to the left. The first element of the array should "wrap around" to the last element Exampl Here's an example array. The parameters to the function represent the addresses of array[0] and array[size-1]. Before the function call array[o array[size-1 17 4 2 After the function call arrayro 17 array[size-1] 4 Your function should work for any size array. You will have to calculate the size. The size is "not" one of the parameters 2) Write a main function that does the following Prompt the user to enter the size of the array and read the size entered by the user Declare a variable-length array of integers (int) of the size entered by the user. Seed the random number generator using current time . 2) Write a main function that does the following . Prompt the user to enter the size of the array and read the size entered by the user . Declare a variable-length array of integers (int) of the size entered by the user . Seed the random number generator using current time .Prompt the user to enter maximum possible value for array elements (max) .Fill the array with random numbers between 1 and max (inclusive) .Print the array Call the shiftLeft function .Print the array again Note: you may reuse your fillArray and neatPrint functions from Lab 3 if you like Part 2 (Calculating Circle Circumference, Circle Area or Sphere Volume Using Function Pointers) Create a text-based, menu-driven program that allows the user to choose whether to calculate the circumference of a circle, the area of a circle or the volume of a sphere. The program should then input a radius from the user, perform the appropriate calculation and display the result. Use an array of function pointers in which each pointer represents a function that returns void and receives a double parameter. The corresponding functions should each display messages indicating which calculation was performed, the value of the radius and the result of the calculation. Use the constant value 3.14159 for . Call the program part2. c Use the code in Fiqure 7.28 of the book (Demonstrating an array of pointers to functions) as a model Use the while loop to process the user's choice (as in Figure 7.28). When the user enters 0, the circumference of a circle should be computed. When the user enters 1, the area of a circle should be computed. When the user enters 2, the volume of a sphere should be computed. When the user enters 3, the program should terminate Sample run of the program may look like the following Enter 0 for circumference, 1 for area, 2 for volume, 3 to end: 1 Please enter radius 2 The area of a circle is computed. Radius: 2.000000 Area: 12.566360 Enter 0 for circumference, 1 for area, 2 for volume, 3 to end: 0 Please enter radius: 1 The circumference of a circle is computed. Radius: 1.000000 Circumference: 6.283180 Enter 0 for circumference, 1 for area, 2 for volume, 3 to end: 2 Please enter radius: 3 The volume of a sphere is computed Radius: 3.000000 Volume: 113.097240 Enter 0 for circumference, 1 for area, 2 for volume, 3 to end: 3 Program execution completed Part 3 (Telephone-Number Word Generator) Standard telephone keypads contain the digits 0 through 9. The numbers 2 through 9 each have three letters associated with them, as is indicated by the following table Digit 2 Letter A BC DE F G HI JKL Digit Letter M N O PRS TUV WXY 7 4 (Note: to make it simpler, there is no 'Q' in the table) Many people find it difficult to memorize phone numbers, so they use the correspondence between digits and letters to develop seven-letter words that correspond to their phone numbers. For example, a person whose telephone number is 686-2377 might use the correspondence indicated in the above table to develop the seven- letter word "NUMBERS." Businesses frequently attempt to get telephone numbers that are easy for their clients to remember. If a business can advertise a simple word for its customers to dial, then, no doubt, the business will receive a few more calls Each seven-letter word corresponds to exactly one seven-digit telephone number. The restaurant wishing to increase its take-home business could surely do so with the number 825-3688 (i.e., "TAKEOUT) Each seven-digit phone number corresponds to many separate seven-letter words. Unfortunately, most of these represent unrecognizable juxtapositions of letters. It is possible, however, that the owner of a barber shop would be pleased to know that the shop's telephone number, 424-7288, corresponds to "HAIRCUT." The owner of a liquor store would, no doubt, be delighted to find that the store's telephone number, 233-7226, corresponds to "BEERCAN." A veterinarian with the phone number 738-2273 would be pleased to know that the number corresponds to the letters "PETCARE." Write a C program that, given a seven-digit number, writes to a file (called word.txt) every possible seven-letter word corresponding to that number. Each word should be written on a new line. There are 2187 (3 to the seventh power) such words. There should be 2187 lines in the file. Avoid phone numbers with the digits 0 and 1. Call the program part2.d Represent letters corresponding to digits as an array of strings char *phoneLetters [10] {" "ABC", "MNO", "PRS", "TUV", "WXY"); ", " ", "DEF", "GHI", "JKL", = Use array phoneLetters to get letters corresponding to digits. For instance, letters corresponding to digit 4 are phoneLetters [4] [0], phoneLetters [4] [1] , and phoneLetters [4] [2] . You may use 7 nested loops to generate all possible seven-letter words (one loop per digit in the number) Your program should do the following Represent letters corresponding to digits as an array of strings as shown above Prompt the user to enter a seven-digit phone number using the digits 2 through 9 Read the number entered by the user. Writes to a file called word.txt every possible seven-letter word corresponding to that number Part 1 All code in Part 1 goes into one file called part1.c 1) Write a function that accepts two int pointers. The function should be named shiftLeft. There is no returrn value The first parameter is the address of the first element in an array of integers. Think of it as the address of array[O]. The second parameter is the address of the last element in the array. Think of it as array [size - 1]. The function should shift all of the elements one position to the left. The first element of the array should "wrap around" to the last element Exampl Here's an example array. The parameters to the function represent the addresses of array[0] and array[size-1]. Before the function call array[o array[size-1 17 4 2 After the function call arrayro 17 array[size-1] 4 Your function should work for any size array. You will have to calculate the size. The size is "not" one of the parameters 2) Write a main function that does the following Prompt the user to enter the size of the array and read the size entered by the user Declare a variable-length array of integers (int) of the size entered by the user. Seed the random number generator using current time . 2) Write a main function that does the following . Prompt the user to enter the size of the array and read the size entered by the user . Declare a variable-length array of integers (int) of the size entered by the user . Seed the random number generator using current time .Prompt the user to enter maximum possible value for array elements (max) .Fill the array with random numbers between 1 and max (inclusive) .Print the array Call the shiftLeft function .Print the array again Note: you may reuse your fillArray and neatPrint functions from Lab 3 if you like Part 2 (Calculating Circle Circumference, Circle Area or Sphere Volume Using Function Pointers) Create a text-based, menu-driven program that allows the user to choose whether to calculate the circumference of a circle, the area of a circle or the volume of a sphere. The program should then input a radius from the user, perform the appropriate calculation and display the result. Use an array of function pointers in which each pointer represents a function that returns void and receives a double parameter. The corresponding functions should each display messages indicating which calculation was performed, the value of the radius and the result of the calculation. Use the constant value 3.14159 for . Call the program part2. c Use the code in Fiqure 7.28 of the book (Demonstrating an array of pointers to functions) as a model Use the while loop to process the user's choice (as in Figure 7.28). When the user enters 0, the circumference of a circle should be computed. When the user enters 1, the area of a circle should be computed. When the user enters 2, the volume of a sphere should be computed. When the user enters 3, the program should terminate Sample run of the program may look like the following Enter 0 for circumference, 1 for area, 2 for volume, 3 to end: 1 Please enter radius 2 The area of a circle is computed. Radius: 2.000000 Area: 12.566360 Enter 0 for circumference, 1 for area, 2 for volume, 3 to end: 0 Please enter radius: 1 The circumference of a circle is computed. Radius: 1.000000 Circumference: 6.283180 Enter 0 for circumference, 1 for area, 2 for volume, 3 to end: 2 Please enter radius: 3 The volume of a sphere is computed Radius: 3.000000 Volume: 113.097240 Enter 0 for circumference, 1 for area, 2 for volume, 3 to end: 3 Program execution completed Part 3 (Telephone-Number Word Generator) Standard telephone keypads contain the digits 0 through 9. The numbers 2 through 9 each have three letters associated with them, as is indicated by the following table Digit 2 Letter A BC DE F G HI JKL Digit Letter M N O PRS TUV WXY 7 4 (Note: to make it simpler, there is no 'Q' in the table) Many people find it difficult to memorize phone numbers, so they use the correspondence between digits and letters to develop seven-letter words that correspond to their phone numbers. For example, a person whose telephone number is 686-2377 might use the correspondence indicated in the above table to develop the seven- letter word "NUMBERS." Businesses frequently attempt to get telephone numbers that are easy for their clients to remember. If a business can advertise a simple word for its customers to dial, then, no doubt, the business will receive a few more calls Each seven-letter word corresponds to exactly one seven-digit telephone number. The restaurant wishing to increase its take-home business could surely do so with the number 825-3688 (i.e., "TAKEOUT) Each seven-digit phone number corresponds to many separate seven-letter words. Unfortunately, most of these represent unrecognizable juxtapositions of letters. It is possible, however, that the owner of a barber shop would be pleased to know that the shop's telephone number, 424-7288, corresponds to "HAIRCUT." The owner of a liquor store would, no doubt, be delighted to find that the store's telephone number, 233-7226, corresponds to "BEERCAN." A veterinarian with the phone number 738-2273 would be pleased to know that the number corresponds to the letters "PETCARE." Write a C program that, given a seven-digit number, writes to a file (called word.txt) every possible seven-letter word corresponding to that number. Each word should be written on a new line. There are 2187 (3 to the seventh power) such words. There should be 2187 lines in the file. Avoid phone numbers with the digits 0 and 1. Call the program part2.d Represent letters corresponding to digits as an array of strings char *phoneLetters [10] {" "ABC", "MNO", "PRS", "TUV", "WXY"); ", " ", "DEF", "GHI", "JKL", = Use array phoneLetters to get letters corresponding to digits. For instance, letters corresponding to digit 4 are phoneLetters [4] [0], phoneLetters [4] [1] , and phoneLetters [4] [2] . You may use 7 nested loops to generate all possible seven-letter words (one loop per digit in the number) Your program should do the following Represent letters corresponding to digits as an array of strings as shown above Prompt the user to enter a seven-digit phone number using the digits 2 through 9 Read the number entered by the user. Writes to a file called word.txt every possible seven-letter word corresponding to that number

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beyond Big Data Using Social MDM To Drive Deep Customer Insight

Authors: Martin Oberhofer, Eberhard Hechler

1st Edition

0133509796, 9780133509793

Students also viewed these Databases questions

Question

Explain the need for a new field of financial therapy.

Answered: 1 week ago

Question

List the activities involved in employer-designed HRD programs

Answered: 1 week ago