Description
Introduction to C Programming I
Summary: In this homework, you will implement a set of programs to practice working in the C language under Linux.
1 Background
In this assignment, you will practice the C programming language, and try doing program development on Linux. You will work on a set of programs that introduce the basic syntax of C, the structure of programs, scoping rules, and data types. Since C is a new programming language for many students, the programs you will be writing in this assignment will be a bit simpler than the programs you are used to developing. We ask that you do your program development on GCC compiler under Linux. For this rst assignment, you will use the CLion IDE to access the GCC compiler.
For this module, there is a set of videos that describe how to install Xubuntu and CLion on a virtual machine. By following those instructions, you will be able to run a “virtual” instance of Xubuntu (a variant of the common Ubuntu Linux distribution) on your computer. CLion is an IDE for the C language that is related to the IntelliJ IDE for Java. For this assignment, you should plan to use it to develop your C programs. Note that IDEs aren’t as common on Linux as on other operating systems. Many developers write code primarily from a “command prompt” environment called the terminal. This is to be discussed at a later time.
In this assignment, you will work on three programs. In the rst, you will debug an existing program. Some of the bugs that this program contains are not issues that can arise in a language like Java. In the second, you will develop a program to read data from the user and perform a computation based on what they enter. In the third, you will develop a program that manipulates C-style strings to decrypt a message.
This document is separated into three sections: Background, Requirements, and Submission. You have almost nished reading the Background section already. In Requirements, we will discuss what is expected of you in this homework. Lastly, Submission discusses how your source code should be submitted on Canvas.
2 Requirements [28 points]
For this assignment you will write a series of three small programs to practice programming in C. Your programs must compile and run under Xubuntu (or another variant of Ubuntu) 22.04. If you follow the video sequence on installing CLion for Xubuntu, you will have this development environment available. For two of these programs, you must start from the attached base les. For the other program, you will be expected to write it from scratch.
2.1 Computation (hw02a_base.c) [8 points]
Add a prompt for the number of cylinders to sum. Make sure to use the control symbol for integers.
[2 points]
Create a loop based on the number of cylinders the user enters. [1 points]
Within the loop, prompt for height and radius parameters (allow oating point numbers), and calculate the volume for that particular cylinder. [4 points]
Display the total volume sum back to the user. Make sure to use the right control symbol. [1 points]
2.2 Collatz (no base le) [8 points]
For this program, consider the following pseudocode algorithm for checking if a particular positive integer satis es the collatz conjecture:
Algorithm 1 Collatz conjecture checker.
termination (n) { //pre=condition : n is any integer
while n not equal 1 do { i f even(n)
then n := n/2
else n := 3n+1
}
output (n) // post=condition : n=1
}
Write a C program to implement the algorithm as a function called termination that is called from main. [4 points]
Call termination from main on an input integer given by the user. [2 points]
Count and display how many iterations are executed for the input. [2 points]
2.3 Decryption (hw02b_base.c) [12 points]
For this program, you will write a chunk based decryption program. Study the base code and make the following changes:
Implement display_chunks(). Loop over each string in the array of message chunks (strings) and print it. Each chunk should be printed back to back, do not insert an extra newline. Do not print the rst character in each string since it is only used to store the order of the chunks. (Hint: use pointer arithmetic to skip a character.) [2 points]
3 Submission
The submission for this assignment has one part: a source code submission. The les should be attached to the homework submission link on Canvas.
Writeup: For this assignment, no write up is required.
Source Code: Name your les as LastNameComputation.c , LastNameCollatz.c , “LastNameDecrypt.c” (e.g. “AcunaComputation.c , AcunaCollatz.c , and AcunaDecrypt.c”).
Reviews
There are no reviews yet.