首页
网站开发
桌面应用
管理软件
微信开发
App开发
嵌入式软件
工具软件
数据采集与分析
其他
首页
>
> 详细
LP101留学生程序辅导、讲解c++程序、c/c++编程语言调试 解析Java程序|解析C/C++编程
项目预算:
开发周期:
发布时间:
要求地区:
Homework 4 -- Math
CS110/EIE110/LP101 2020 Fall
Macau Univ. of Sci. and Tech.
Instructor: Zhiyao Liang
1 Introduction
Math is important for a student. We have learned fundamental arithmetic operators of + - * / in our primary schools, and we have learned
recently the operation of matrix multiplication in Linear Algebra. In this homework, we want to write a C program that can help students to lean
these important math operations by solving problems like what are shown in the above pictures [1][2]
.
2. Knowledge points
The emphasized knowledge aspects in this homework include the following:
Struct
Enum
Use malloc() or calloc() to dynamically create objects on the heap memory.
Linked list (singly linked list)
Function with array arguments.
Multi-dimensional array.
Design and implement functions.
File reading and writing.
Design a program with multiple files.
The main function with command line arguments.
Friendly interaction between the computer and the user.
User's menu of choices
Show friendly and clear messages to a user.
Clear input queue when needed. This is a technique to avoid input confusion.
When user's input is wrong, show some error message, and ask the user to do input again.
We will write a C program that will perform different operations on strings. The program is organized using multiple functions and files.
Algorithms: matrix multiplication.
2 Introduction of tasks of this homework
2.1 Arithmetic problems
The program will let a user ( a student) do exercises of arithmetic problems. For example, consider the following 5 problems:
11 + 25 = ?
79 - 32 = ?
80 * 20 = ?
45 / 9 = ?
79 + 21 = ?
These problems can be saved in a file. A possible choice of the file content is using 3 sequences of strings: a sequence of numbers, a sequence of
operators, and a sequence of numbers, like the following:
11 79 80 45 79
+ - * / +
25 32 20 9 21
We want the program to be able to do the following
Create new problems. For example, in order to generate 5 problem, then program can generate a list of 5 random integers, and a list of 5
random operators, and a list of 5 random integers.
Write the created problems into some file, so that they can be used again later.
Read a list of problems from a file which contains some problems that are written into the file by this program earlier.
Modify the list of problems, like
Adding a problem to the list.
Deleting a problem from a list.
Changing a problem in a list. For example, changing 79 - 32 to 79 + 57 .
2.1.1 Hints on a list of arithmetic problems.
We will use linked lists to record the arithmetic problems, not arrays. A sequence of problems (each problem has the form
number1 operator number2 ) can be recorded in two ways using lists
1. Using three linked lists with the same length.
a list of number1
a list of operators
a list of number2
2. Using just one linked list, where each node contain the three pieces of information of a problem: number1, operator, and number2. You can
make them as three members in a structure of a node; Or you can create a structure Problem containing the three members while Problem
is a member of a node.
The following hints are on the file that saves a sequence of problems.
The format of the file can be decided by you. One choice that is shown above is using three lines.
It can be easier to open a file for reading and writing in text mode by a call like fopen(filename, mode) .
To read an integer from a file, we can use fscanf(fileName, "%d", &varName) .
To read an operator from a file, we can use fscanf(fileName, "%s", charArrayName) , this will read a string with one character (besides the
null character).
To write an integer or an operator into a file, we can use the corresponding calls of the fprintf() function. Make sure that the numbers and
operators are separated by at least a single white space character in the file.
To generate a random integer, we can call the rand() or srand() functions. An introduction to use these function can be found at:
https://www.dummies.com/programming/c/how-to-generate-random-numbers-in-c-programming/
2.2 Matrix multiplication
A matrix can be represented by different ways, including the at least the following:
A two-dimensional array, where the two dimensions correspond to the number of rows and columns of the matrix respectively.
A structure containing three members:
the number of rows
the number of columns
the sequence of integers in the matrix, which is a one-dimensional array, or a pointer to the first element of such an array. We know the
idea that multi-dimensional array can be represented by a one-dimensional array.
3. Tasks of the program.
3.1 User menu
When the program runs, an user sees a menu containing choices like the following:
a: create a sequence of arithmetic problems.
b: show a sequence arithmetic problems.
c: save a sequence arithmetic problems to a file.
d: load a sequence arithmetic problems from a file.
e: add a problem to the sequence of arithmetic problems.
f: change a problem in the a sequence of arithmetic problems.
g: delete a problem from the sequence of arithmetic problems.
h: show the correct answers of the sequence of arithmetic problems.
i: create a problem of matrix multiplication problem.
j: show the correct answer of the matrix multiplication problem.
q: quit
The tasks related to theses choices are described in details in the following sections.
3.2 Data storage
The program should have (at least) the following data in memory:
Storage of a sequence of arithmetic problems. Linked lists should be used. As described earlier, you can use three linked lists or just one
linked list. When a new sequence of problems is created they are saved in these lists; When a sequence of problems are loaded from a file,
they are saved in these lists and the previous data in these lists will be deleted.
Storage of three matrixes: two matrixes participate in a multiplication, while the other record the result to be computed.
A file name. The file to write problems into and read problems from.
3.3 File name
The file name should be given from command-line arguments. For example, when the program has been compiled and an executable file
myProgram.exe is generated (on Windows), then the command-line command:
myProgram problems.txt
specifies that the file name is problems.txt . The file with the name may or may not exist. When you write new data into this file, you can decide if
the data will be appended to this file, or the file's content will be deleted and replaced the new data.
3.4 Choice a
The number of problems should be decided in the program, maybe some symbolic constant.
A sequence of arithmetic problems will be generated, whose numbers and operators are randomly chosen.
The generated problems is saved in memory using linked lists.
3.5 Choice b
The sequence of arithmetic problems are printed on screen in some clear and proper way. The nodes in the list will be accessed one by one. If the
list is empty, print some message saying that no problem is created.
3.6 Choice c
A file stream should be opened using fopen() , better with a text mode argument. The sequence of arithmetic problems will be written to the
stream. The format of the file should be proper.
3.7 Choice d
This is the opposite operation of Choice c. The file content is read from a file stream and saved into some list (or lists) of node. Before reading from
the stream, make sure that its reading position should be at the beginning of the file (maybe call the rewind() function) The previously saved data
in the lists should be released ( free() ).
3.8 Choice e
Create new arithmetic problem, record it as some node and append the node to the list. If you use three linked lists, then three nodes should be
appended to the three lists.
3.9 Choice f
Find the middle node in the list. If there are 9 nodes in the list, then the middle one is the 5
th node. If there are 10 nodes in the list, then the 5
th or
6
th node is the middle one. Replace the problem data in the node with some random number and operator.
3.10 Choice g
Find the middle node in the list and delete it. The space of the deleted node should be released. The left neighbor and right neighbor of the deleted
node should be connected to make the list unbroken.
3.11 Choice h
Print the correct answers of the sequence of arithmetic problems. Especially, for division, you can either show some floating point number with
decimal point, or show some fraction. For example, the result of 4 / 6 can be printed as 0.6666 or 2/3 .
[Bonus] If you can show the result of division as some mostly-reduced form of fraction. When number2 of the division is 0, show that the answer is
undefined or Infinity .
3.12 Choice i
Create two matrixes of integers. The size of the two matrixes (number of rows and columns) can be decided by you. But the number of rows of
matrix A should be the same as the number of columns of matrix B, otherwise, some error message should be printed.
Record the two matrixes in some proper way, that has been discussed in Section 2.2.
The integers of the matrixes can be randomly generated, or input from a user, you can decide which way.
3.13 Choice j
Define a function matrix_multiply() that has parameters representing 2 matrixes and compute the result of matrix multiplication. You can define
the proper parameters according to your way of recording a matrix.
The result of matrix multiplication should be recorded as another a matrix, then be printed in some clear way.
3.14 Choice q
Close any opened file stream. Free all space allocated on heap. Then quit and end the program.
3.15 free() and fclose()
When some storage dynamically allocated on the heap memory will not be used anymore, its memory space should be released by calling
free() . Especially, the nodes in a list should be released somewhere in the program.
When a file stream is not used, it should be closed by calling with fclose() .
3.16 Bonus choices
Some bonus points will be given if you can do the following extra tasks:
Implement some menu choice so that a user can provide answers to the arithmetic problems, and some grade will be printed according to the
correct answer.
Implement some menu choice so that a user can provide answer to the problem of matrix multiplication, and some result can be printed
saying whether the answer is correct or not.
Implement some menu choice so that the created matrix problem can be saved to, or loaded from some file.
3.17 Other requirements
Design functions properly. Arrange your code in several .c or .h files. Compile and test your program. For using library functions, check the related
documents on some website like https://en.cppreference.com or cplusplus.com
Submission
Upload your files at the webpage address of this homework on Moodle.
The uploaded files can include only the following:
The source files (.c and .h files),
An optional document file (.txt, .md, .docx) describing your work, like: what features of the homework are achieved; what are the
remaining problems; how did you solve the difficulties that you met, some screen record of compiling and running the program ...
About homework submission in a group:
at most 3 students can form a group to submit the homework. You can surely do the homework alone.
One group only need to submit the homework by once by one student. The other members do not need to submit anything, or just
submit one .txt file saying who are the members of the group and who submitted the homework.
In each file that you submit, record the names in Chinese (if you are not an international student) and English letters, classes of each
student, last 5 digits of student ID, as comments. For example:
/* homework 4. Group members:
李⽩ Li, Bai CS110 D1
杜甫 Du, Fu EIE110 D2
李清照 Li, Qingzhao CS110 D3
*/
Deadline: Saturday January 9 2021 11:00pm
Reference
1. "Mathematics at Buckingham Park" http://www.buckinghampark.bucks.sch.uk/mathematics.html
2. "什麼是單鏈表, 鏈式存儲結構詳解" http://c.biancheng.net/view/3336.html
3. “CS140 Lecture notes -- Singly Linked Lists” http://web.eecs.utk.edu/~bvanderz/teaching/cs140Fa09/notes/Slist/
4. "C Primer Plus", Stephen Prata, Edition:6, ISBN:9780321928429, Publisher:Addison-Wesley Professional, 2013.
5. "C Programming Language", Brian W. Kernighan and Dennis Ritchie, Edition:2, ISBN:9780131193710, Publisher:Prentice Hall, 1988.F
1. https://tse4-mm.cn.bing.net/th/id/OIP.9SPCMjuApIsggRTvd7fu_gAAAA?pid=Api&rs=1 ↩
2. https://doyouremember.com/wp-content/uploads/2019/03/Viral-Math.jpg ↩
软件开发、广告设计客服
QQ:99515681
邮箱:99515681@qq.com
工作时间:8:00-23:00
微信:codinghelp
热点项目
更多
代写math 1151, autumn 2024 w...
2024-11-14
代做comp4336/9336 mobile dat...
2024-11-14
代做eesa01 lab 2: weather an...
2024-11-14
代写comp1521 - 24t3 assignme...
2024-11-14
代写nbs8020 - dissertation s...
2024-11-14
代做fin b377f technical anal...
2024-11-14
代做ceic6714 mini design pro...
2024-11-14
代做introduction to computer...
2024-11-14
代做cs 353, fall 2024 introd...
2024-11-14
代做phy254 problem set #3 fa...
2024-11-14
代写n1569 financial risk man...
2024-11-14
代写csci-ua.0202 lab 3: enco...
2024-11-14
代写econ2226: chinese econom...
2024-11-14
热点标签
mktg2509
csci 2600
38170
lng302
csse3010
phas3226
77938
arch1162
engn4536/engn6536
acx5903
comp151101
phl245
cse12
comp9312
stat3016/6016
phas0038
comp2140
6qqmb312
xjco3011
rest0005
ematm0051
5qqmn219
lubs5062m
eee8155
cege0100
eap033
artd1109
mat246
etc3430
ecmm462
mis102
inft6800
ddes9903
comp6521
comp9517
comp3331/9331
comp4337
comp6008
comp9414
bu.231.790.81
man00150m
csb352h
math1041
eengm4100
isys1002
08
6057cem
mktg3504
mthm036
mtrx1701
mth3241
eeee3086
cmp-7038b
cmp-7000a
ints4010
econ2151
infs5710
fins5516
fin3309
fins5510
gsoe9340
math2007
math2036
soee5010
mark3088
infs3605
elec9714
comp2271
ma214
comp2211
infs3604
600426
sit254
acct3091
bbt405
msin0116
com107/com113
mark5826
sit120
comp9021
eco2101
eeen40700
cs253
ece3114
ecmm447
chns3000
math377
itd102
comp9444
comp(2041|9044)
econ0060
econ7230
mgt001371
ecs-323
cs6250
mgdi60012
mdia2012
comm221001
comm5000
ma1008
engl642
econ241
com333
math367
mis201
nbs-7041x
meek16104
econ2003
comm1190
mbas902
comp-1027
dpst1091
comp7315
eppd1033
m06
ee3025
msci231
bb113/bbs1063
fc709
comp3425
comp9417
econ42915
cb9101
math1102e
chme0017
fc307
mkt60104
5522usst
litr1-uc6201.200
ee1102
cosc2803
math39512
omp9727
int2067/int5051
bsb151
mgt253
fc021
babs2202
mis2002s
phya21
18-213
cege0012
mdia1002
math38032
mech5125
07
cisc102
mgx3110
cs240
11175
fin3020s
eco3420
ictten622
comp9727
cpt111
de114102d
mgm320h5s
bafi1019
math21112
efim20036
mn-3503
fins5568
110.807
bcpm000028
info6030
bma0092
bcpm0054
math20212
ce335
cs365
cenv6141
ftec5580
math2010
ec3450
comm1170
ecmt1010
csci-ua.0480-003
econ12-200
ib3960
ectb60h3f
cs247—assignment
tk3163
ics3u
ib3j80
comp20008
comp9334
eppd1063
acct2343
cct109
isys1055/3412
math350-real
math2014
eec180
stat141b
econ2101
msinm014/msing014/msing014b
fit2004
comp643
bu1002
cm2030
联系我们
- QQ: 9951568
© 2021
www.rj363.com
软件定制开发网!