C语言代写/C代写:Assignment4 – MakefilesandFunctionPointers

C语言代写/C代写:这是一个基础的C作业,涉及makefile相关的内容
Assignment4 – MakefilesandFunctionPointers
• The problems of this assignment must be solved in C.
• Your programs should have the input and output formatting according to the testcases listed after the problems.
Problem 4.1 Makefile (2 points) Presence assignment, due by 18:30 h today
Continue with your solution for Problem 3.4 in the following manner: write and upload a Make- file called “Makefile.txt” which has multiple targets and can be used to: 1) generate all object files corresponding to the source files, 2) generate executable code from the object files and 3) delete all files except source files.
Submit the three source files and the makefile called “Makefile.txt”. You can assume that the input will be valid.
Problem 4.2 Simple function pointers (2 points) Write a program that reads a string and then repeatedly reads a command (one character) from the standard input.
If you enter ’a’, then the string should be printed in uppercase on the standard output.
If you enter ’b’, then the string should be printed lowercase on the standard output.
If you enter ’c’, then lowercase characters should be printed uppercase and uppercase characters are printed lowercase on the standard output.
If you enter ’d’, then the program should quit the execution of the program.
Your main function or any other function where you read the commands may not contain any if or switch statements for mapping the command to which function should be called. Your main function should contain an endless while loop.
Implement the solution using function pointers. The original string should not be changed.
You can assume that the input will be valid.
Testcase 4.2: input
This is a String
a
b
c
b a d
number is 3 then the program should quit execution.
Your main function or any other function where you read the characters and the numbers may not contain any if or switch statements, but an endless while loop for repeated input.
Your program should use function pointers and for sorting you should use the function qsort() from stdlib.h.
You can assume that the input will be valid.
Problem 4.3
Quicksort with function pointers
(2 points) Write a program that sorts an array of n characters. After reading n and the values of the array from the standard input, the program reads an integer number and if this number is 1 then the sorting should be ascending, if the number is 2 then the sorting should be descending and if the
Testcase 4.2: output
THIS IS A STRING
this is a string
tHIS IS A sTRING
this is a string
THIS IS A STRING
Testcase 4.3: input
Testcase 4.3: output
edcba abcde
5 b d a e c 2 1 3
Problem 4.4
Bubblesort with function pointers
(4 points) Write a program that reads an array of the following structure and sorts the data in ascending
order by title or publication year using the bubblesort algorithm.
struct book {
char title[45];
int year;
};
Your program should read the number of books from the standard input followed by the array of data corresponding to the books. You should print the lists of sorted books in ascending order with respect to their title (alphabetical order) and with respect to their publication year. Within the sorting according to the title, note that if multiple books have the same title, then they should be sorted ascending with respect to their publication year. Within the sorting according to year, note that if multiple books have the same publication year, then they should be sorted alphabetically with respect to their name.
Instead of writing two sorting functions use function pointers such that you can implement a generic bubblesort function able to sort according to different criteria.
You can assume that the input will be valid.
The pseudocode of the bubblesort algorithm is the following:
repeat
swapped = false
for i = 1 to length(A) – 1 inclusive do: /∗ if this pair is out of order ∗/
if A[i-1] > A[i] then
/ ∗ swap them and remember swap( A[i-1], A[i] ) swapped = true
end if end for
until not swapped
Testcase 4.4: input
3
Algorithms and Data Structures
1993
Java Programming
2001
C Programming
1987
something
changed
∗ /
Testcase 4.4: output
By title:
{Algorithms and Data Structures, 1993}
{C Programming, 1987}
{Java Programming, 2001}
By year:
{C Programming, 1987}
{Algorithms and Data Structures, 1993}
{Java Programming, 2001}

发表评论

电子邮件地址不会被公开。 必填项已用*标注