CSCI 2122 - Systems Programming - lab3 Flow Control, Arrays, and Bitwise Operations


  • 作业标题:CSCI 2122 - Systems Programming - lab3 Flow Control, Arrays, and Bitwise Operations
  • 课程名称:Dalhouse University CSCI 2122 Systems Programming
  • 完成周期:2天

1. Introduction

This lab is designed to introduce you to some of the programming structures you’re probably used to from other languages, such as strings, if statements, and loops. There are likely some other things explained here that you might not have dealt with, such as bitwise operations, recursion, switch statements, and low level arrays. By the end of this lab, you will be expected to understand the following:

  1. Booleans ( Bool type from C99).
  2. Bitwise operations.
  3. Arrays and how they work in C (without pointers).
  4. Strings and how they work in C.
  5. Conditional Statements (if, if-else, ternary, switch).
  6. Loops (while, do-while, for).
  7. Simple recursion.

The proceeding labs will build and expand this knowledge into the realm of low level computing, including memory management, data structures, methods for approaching low-level computation, and a variety of other subjects. As such, knowing these key principles will be important for future programming and development.

In this lab you are expected to perform the basics of cloning your Lab 3 repository from the GitLab course group. A link to the course group can be found here and your repository can be found in the Lab3 subgroup. See the Lab Technical Document for more information on using git. You will notice that your repository has a file in the Lab3 directory named delete this file. Due to the limitations of GitLab, we are not able to push completely empty directories. Before your push your work to your repository (which should be in the Lab3 directory anyway), make sure to first use the git rm command to remove the extra file. If you do not, your pipeline will fail.

2. Booleans

You may have noticed in your reading of data types in C that booleans are rarely mentioned. In the early days of C, such as C89, there was no concept of a boolean type in the C standard. Instead, programmers would use preprocessor directives and/or typedef statements to create their own boolean data types, often called bool. Normally bool types were just masks for char, short, or int types where 0 was false and 1 was true. As of C99, the Bool type has been introduced, which holds a 0 or a 1 to represent a boolean value. It’s likely the name Bool was chosen to ensure the previous bool type definitions wouldn’t conflict with the new type. For programmers with no potential for boolean type conflicts, the stdbool.h library was created for the POSIX 2008 standard (which has since been adopted into the ISO C Standard), which helps alleviate some of the issues created by introducing the Bool type. First, it provides a clearer definition for true and false types, which has helped prevent preprocessor directives having their text replaced by other overzealous directives.

Second, it provides a regular #define directive so that bool can be used in place of Bool.
If you want to use the built-in boolean type, be sure to import the library and compile your code with at least the C99 standard. As mentioned previously, all test and marking scripts will be compiled using the C18 standard to ensure as much compatibility as possible.

。。。

3. Lab 3 Function Contracts

In this lab you will be responsible for fulfilling five lab contracts: the libraries contract, the pascal contract, the primes contract, the adjacent products contract, and the bit encryption contract. Each contract is designed to test you on some of the things you’ve learned throughout the instruction portion of this lab. All contracts must be completed exactly as the requirements are laid out. Be very careful to thoroughly read the contract instructions before proceeding.

This does not, however, preclude you from writing more functions than you are asked for. You may write as many additional functions as you wish in your C source file, except in the libraries contract, which has very specific requirements. All contracts are designed to be submitted without a main function, but that does not mean you cannot write a main function in order to test your code yourself while you’re writing your programs. It may be more convenient for you to write a C source file with a main function by itself and take advantage of the compiler’s ability to link files together by accepting multiple source files as inputs. When you push your code to Gitlab, you don’t need to git add any of your extra main function source files.

The programs you write for this lab will be compiled using your ‘Lab3/lib‘ folder as a source for headers, meaning any functions contained within mmath.h and mstring.h will be explicitly compiled. The compiler will also be run with the -lm flag, in case you need to import the math library. For those of you who are concerned, when deciding which naming conventions you want to use in your code, favour
consistency in style, not dedication to a style that doesn’t work. The contracts in this document are worth the following points values, for a total of 10.

。。。


文章作者: IT神助攻
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 IT神助攻 !
  目录