wujr5 / c-and-cpp-language-learning

C和C++编程语言学习 - 2015级
67 stars 34 forks source link

软件:Course Project #41

Open ghostbody opened 8 years ago

ghostbody commented 8 years ago

C Programming : Course Project


Update History

2015/12/9 22:30 Update deadline, a day ahead. 2015/12/9 22:54 Update Presentation, add a presentation for framework discuss 2015/12/11 12:00 Simplify the project requirement

Abstract

Many basically and widely used system are using C language because it's fast and more closed to the underlying of the computer structure. We are going to build a system as a real world project to understand the system design as well as a system implement.

Modeling is very important in process oriented programming. You are going to design the system yourself and design a good file structure with .h files and .c files. And also you should design good function prototypes and make clear the usage of each part.

What's more is that you should implement the functions for the complete logic.

We are going to build a student management system.

Targets

  1. Improve the C language grammar learning.
  2. Learn to design a system using process-oriented programming.
  3. Learn to use modeling method to implement each part of the process.
  4. Learn how to work for a project in Software Engineering.
  5. Learn code style deeply.

    Develop Environment

windows: commandline or DEV cpp ubuntu linux: command line (optional bonus) ubuntu linux using command line and makefile (optional bonus)

使用linux开发可以加分,期末考试很可能使用linux系统。 另外,ftp上有相关虚拟机和镜像文件下载,以及安装教程,入门教程等。

Requirements

Introduction

Now, you are the system designer for our student grading system. And the our course need the following functions, you job is to implement the system demands.

1. Append Records:

You can insert a grade record into the system. The record include the several properties studentID, studentName, studentClass, studentGrade. You can also insert a number of this kind of records at the same time.

2. Delete Records:

You can delete a Record from the system by a studentID, a studentName or a wholeClass, a range of grade. You can also delete a number of this kind of records at the same time.

3. Modify Records:

You can modify the records. For example, I can change a student's name, a student's class or a student's grade. You can also modify a number of this kind of records at the same time.

4. Querying Records:

You can query some students that meets a setting condition. For example, query the students whose grade is less than 60 in a given class. You can also get the max grade, the average grade, the number of students who's grade is greater than 90.

5. Extended Functions:

You can extend the system with other functions (鼓励添加其他功能).

For example, you can use function functional programming. It means that you are supposed to use function pointers to role as filters to meet the requirements more easily. We have note functional programming in optional project 1.

For example:

Student * Query(Student[] stus, bool(*filter)(const void *));


Other Requirements:

Designing Style:

You can not defined useless or meaningless functions. And you can not put all project logic in one file(very bad) or put all logic in a main fuction(very very bad). How to design good function prototypes and how to divide into several files is very important and this will be the most important part for grading.

Coding Style:

Coding style is very important for you. The style rules including google style are required. What's more, you should have good comments with your code.

File Method:

Maybe you will us File IO operation, you can use your own data format. Json or CVS is recommended.

Report Template:

Abstract

Make a brief introduction for your project.

User Documentation

Statements about how to run the program. How to use this system.

Project Structure

Statements about your project structure, i.e. your function interfaces and file structure.

Design Thinking && Design Process

Statements about how you think about the project, i.e. how to divided the project(big question) into smaller questions. Statements about your details of your project design, i.e. how to implement the structure of your system.

Important Algorithm and Data Structure

Some important algorithm and data structure you use should be mentioned. And draw flowchart or write Pseudo code for them.

Testing

Statements about how you test the system.

Conclusion

Personal summary about this project.

Persentation Week 13

We will ask some students to discuss about how to build a framework for the system on Dec 14th 2015.

Presentation Final

We will have a presentation time on January 4th 2016 in the lab class. There will be randomly selected students need to do the presentation.

Deadline:

Dec 31st 2015 18:00 pay attention, one day ahead deadline Dec 30th 2015 18:00 Dec 30th 2015 21:00 And have a good time on new year's eve.

Submit

Submit to the course ftp

ftp://172.18.182.75

username:c_and_cpp password:c_and_cpp

filename : 13331314_叶嘉祺_CourseProject.zip

ghostbody commented 8 years ago

HINT: Three-tier architecture (三层构架)

You will find it very hard to start up, here is an optional design idea.

Three-tier architecture is a client–server software architecture pattern in which the user interface (presentation), functional process logic ("business rules"), computer data storage and data access are developed and maintained as independent modules, most often on separate platforms.[3] It was developed by John J. Donovan in Open Environment Corporation (OEC), a tools company he founded in Cambridge, Massachusetts.

Apart from the usual advantages of modular software with well-defined interfaces, the three-tier architecture is intended to allow any of the three tiers to be upgraded or replaced independently in response to changes in requirements or technology. For example, a change of operating system in the presentation tier would only affect the user interface code.

Typically, the user interface runs on a desktop PC or workstation and uses a standard graphical user interface, functional process logic that may consist of one or more separate modules running on a workstation or application server, and an RDBMS on a database server or mainframe that contains the computer data storage logic. The middle tier may be multitiered itself (in which case the overall architecture is called an "n-tier architecture").

Three-tier architecture:

From wikipedia

Presentation tier (表示层) This is the topmost level of the application. The presentation tier displays information related to such services as browsing merchandise, purchasing and shopping cart contents. It communicates with other tiers by which it puts out the results to the browser/client tier and all other tiers in the network. (In simple terms it is a layer which users can access directly such as a web page, or an operating systems GUI)

Application tier (business logic, logic tier, or middle tier) (应用层或业务逻辑层) The logical tier is pulled out from the presentation tier and, as its own layer, it controls an application’s functionality by performing detailed processing.

Data tier (底层数据访问层) The data tier includes the data persistence mechanisms (database servers, file shares, etc.) and the data access layer that encapsulates the persistence mechanisms and exposes the data. The data access layer should provide an API to the application tier that exposes methods of managing the stored data without exposing or creating dependencies on the data storage mechanisms. Avoiding dependencies on the storage mechanisms allows for updates or changes without the application tier clients being affected by or even aware of the change. As with the separation of any tier, there are costs for implementation and often costs to performance in exchange for improved scalability and maintainability.

1:数据访问层:主要是对非原始数据(数据库或者文本文件等存放数据的形式)的操作层,而不是指原始数据,也就是说,是对数据的操作,而不是数据库,具体为业务逻辑层或表示层提供数据服务。在我们的项目中,数据访问应该是对数据文件的访问。

底层设计数据的读写,主要是文件读写操作。

请参考c语言文件读写章节。

思考问题: 1.如何存储信息?需要什么格式? 2.如何根据已有信息,读取信息? 3.如何根据已有信息,修改信息?

2:业务逻辑层:主要是针对具体的问题的操作,也可以理解成对数据层的操作,对数据业务逻辑处理,如果说数据层是积木,那逻辑层就是对这些积木的搭建。逻辑层主要解决需求中各个功能模块的逻辑问题,如查询成绩等。

3:界面层:在我们的项目中主要表现为CLI-UI(命令行界面)。你需要有一个完整的前端来提示用户来跟你进行交互。 类似下图系统:

image

有能力的同学可以实现GUI

ghostbody commented 8 years ago

Hint: 函数原型设计原则参考

1、原则上尽量少使用全局变量,因为全局变量的生命周期太长,容易出错,也会长时间占用空间.各个源文件负责本身文件的全局变量,同时提供一对对外函数,方便其它函数使用该函数来访问变量。 比如:niSet_ValueName(…);niGet_ValueName(…);不要直接读写全局变量,尤其是在多线程编程时,必须使用这种方式,并且对读写操作加锁。

2、参数命名要恰当,顺序要合理。 例如编写字符串拷贝函数str_copy,它有两个参数。如果把参数名字起为str1 和str2,例如 void str_copy (char str1, char str2); 那么我们很难搞清楚究竟是把str1 拷贝到str2 中,还是刚好倒过来。

可以把参数名字起得更有意义,如叫strSource 和strDestination。这样从名字上就可以看出应该把strSource 拷贝到strDestination。

还有一个问题,这两个参数那一个该在前那一个该在后?参数的顺序要遵循程序员的习惯。一般地,应将目的参数放在前面,源参数放在后面。如果将函数声明为: void str_copy (char strSource, char strDestination); 别人在使用时可能会不假思索地写成如下形式: char str[20]; str_copy (str, “Hello World”); 参数顺序颠倒

3、如果参数是指针,且仅作输入参数用,则应在类型前加const,以防止该指针在函数体内被意外修改。

例如: void str_copy (char strDestination,const char strSource);

4、不要省略返回值的类型,如果函数没有返回值,那么应声明为void 类型。 如果没有返回值,编译器则默认为函数的返回值是int类型的。

5、在函数体的“入口处”,对参数的有效性进行检查。尤其是指针参数,尽量使用assert宏做入口校验,而不使用if语句校验.

6、return 语句不可返回指向“栈内存”的“指针”,因为该内存在函数体结束时被自动销毁。 例如: char * Func(void) { char str[30]; … return str; } str 属于局部变量,位于栈内存中,在Func 结束的时候被释放,所以返回str 将导致错误。

7、函数的功能要单一,不要设计多用途的函数。微软的Win32 API就是违反本规则的典型,其函数往往因为参数不一样而功能不一,导致很多初学者迷惑。

8、函数体的规模要小,尽量控制在80 行代码之内。

9、相同的输入应当产生相同的输出。尽量避免函数带有“记忆”功能。 带有“记忆”功能的函数,其行为可能是不可预测的,因为它的行为可能取决于某种“记忆状态“。这样的函数既不易理解又不利于测试和维护。在C 语言中,函数的static局部变量是函数的“记忆”存储器。建议尽量少用static 局部变量,除非必需。

10、避免函数有太多的参数,参数个数尽量控制在4个或4个以内。如果参数太多,在使用时容易将参数类型或顺序搞错。微软的Win32 API就是违反本规则的典型,其函数的参数往往七八个甚至十余个。比如一个CreateWindow函数的参数就达11个之多。

11、尽量不要使用类型和数目不确定的参数。 C 标准库函数printf 是采用不确定参数的典型代表,其原型为: int printf(const chat *format[, argument]…); 这种风格的函数在编译时丧失了严格的类型安全检查。

12、有时候函数不需要返回值,但为了增加灵活性如支持链式表达,可以附加返回值。例如字符串拷贝函数strcpy 的原型: char strcpy(char strDest,const char *strSrc); strcpy 函数将strSrc 拷贝至输出参数strDest 中,同时函数的返回值又是strDest。这样做并非多此一举,可以获得如下灵活性: char str[20]; int length = strlen(strcpy(str, “Hello World”) );

13、不仅要检查输入参数的有效性,还要检查通过其它途径进入函数体内的变量的有效性,例如全局变量、文件句柄(FILE * 指针)等。

14、函数名与返回值类型在语义上不可冲突。 违反这条规则的典型代表就是C语言标准库函数getchar。几乎没有一部名著没有提到getchar函数,因为它实在太经典,太容易让人犯错误了。所以,每一个有经验的作者都会拿这个例子来警示他的读者,我这里也是如此: char c; c = getchar(); if(EOF == c) { … } 按照getchar 名字的意思,应该将变量c 定义为char 类型。但是很不幸,getchar 函数的返回值却是int 类型,其原型为: int getchar(void); 由于c 是char 类型的,取值范围是[-128,127],如果宏EOF 的值在char 的取值范围之外,EOF 的值将无法全部保存到c 内,会发生截断,将EOF 值的低8 位保存到c 里。这样if 语句有可能总是失败。这种潜在的危险,如果不是犯过一次错,肯怕很难发现。

sugerpocket commented 8 years ago

Ubuntu安装教程在哪,找不到啊= =

Chenxr1997 commented 8 years ago

在资源-计科里面

ghostbody commented 8 years ago

@Fuckingboy https://github.com/wujr5/c-and-cpp-language-learning/issues/34