Assessment 1 Programming In C: Getting Started Overview ✓ Solved
Assessment 1 Programming in C: Getting Started Overview
Write logical, syntactically correct C programs that use proper variables to perform arithmetic calculations. Interact with the user via text in the terminal window. Write C code that is properly commented and formatted.
In this course, you will be using Code::Blocks as your integrated development environment (IDE) for writing, compiling, and running your C programs. The best way to start getting to know the C programming language and the tools you will use in this course is by using them.
This assessment consists of four short programs. Use Code::Blocks to complete your work. You will submit the four C source code files for this assignment. Please zip the files and include your name in the name of the compressed file.
Part 1: Commenting Code - Include comments in source code that explains what the code does and how it does it are an important professional best practice. Type in the code provided in the assignment Resources, build/compile the program, and run it. When you have the code running, go through the code and add comments to explain what the code does and how it does it. You should add at least five comments to the code provided.
Part 2: About You - Create a program that prints three lines of text about yourself. Be sure to include appropriate spacing and new line characters to make the output in the terminal window readable.
Part 3: Integer and Floating Point Arithmetic - Write a single program that prints the results of two arithmetic expressions using integers and the results of two floating-point calculations. Print out both the arithmetic expressions and the answers calculated by the code.
Part 4: User Input - Write a program that prompts the user to enter a character, an integer, and floating point number. After reading the input, the program should print out the values entered.
When you are ready to turn in your assignment, download your .c source code files and zip them together for submission. Requirements include a title page and reference page, if necessary, in APA format, Times New Roman font, 12 pt., double-spaced.
Paper For Above Instructions
The assessment outlined above focuses on foundational skills in C programming designed to transition students from merely using software to creating their own programs. By engaging in practical exercises, learners will deepen their understanding of key programming concepts.
Part 1: Commenting Code
Effective code commenting is vital in programming as it enhances readability and maintainability. Commenting serves as documentation that allows other developers, or even future you, to understand the purpose and functionality of the code. According to Kochan (2014), including comments in code can facilitate communication and collaboration among developers. For this part, I will provide a simple program that adds two numbers together and explain through comments how each part of the code functions.
/ John Doe - IT-FP2240 - u01a1 - Part 1 - 01/01/2023 /
include <stdio.h> // Include standard input-output header
int main() {
int a = 5; // Declare and initialize first integer
int b = 10; // Declare and initialize second integer
int sum; // Declare variable to store sum of a and b
sum = a + b; // Calculate sum
printf("The sum of %d and %d is %d\n", a, b, sum); // Output sum
return 0; // Indicate successful completion
}
Part 2: About You
To showcase basic C programming constructs, let's create a simple program that displays three lines of information about the user:
/ John Doe - IT-FP2240 - u01a1 - Part 2 - 01/01/2023 /
include <stdio.h>
int main() {
printf("My name is John Doe.\n"); // Output name
printf("I am a computer science student.\n"); // Output field of study
printf("I love programming in C!\n"); // Output favorite programming language
return 0; // Indicate successful completion
}
Part 3: Integer and Floating Point Arithmetic
This section requires us to evaluate simple arithmetic expressions involving both integers and floating-point numbers. Here's an example program that satisfies these requirements:
/ John Doe - IT-FP2240 - u01a1 - Part 3 - 01/01/2023 /
include <stdio.h>
int main() {
// Integer arithmetic
int x = 20;
int y = 10;
int int_result = x * y; // Multiply x and y
printf("Integer multiplication: %d * %d = %d\n", x, y, int_result); // Output result
// Floating-point arithmetic
float a = 5.5;
float b = 2.0;
float float_result = a / b; // Divide a by b
printf("Floating-point division: %.2f / %.2f = %.2f\n", a, b, float_result); // Output result
return 0; // Indicate successful completion
}
Part 4: User Input
Lastly, we will design a program to take user input. This part reinforces understanding of functions like scanf() for reading user data:
/ John Doe - IT-FP2240 - u01a1 - Part 4 - 01/01/2023 /
include <stdio.h>
int main() {
char character; // Declare variable for a character
int integer; // Declare variable for an integer
float floating_point; // Declare variable for a floating-point number
// Prompt user for input
printf("Enter a character: ");
scanf(" %c", &character); // Read character input
printf("Enter an integer: ");
scanf("%d", &integer); // Read integer input
printf("Enter a floating point number: ");
scanf("%f", &floating_point); // Read floating point input
// Output the values entered
printf("You entered: '%c', %d, and %.2f\n", character, integer, floating_point);
return 0; // Indicate successful completion
}
Conclusion
Completing these sections of the assessment demonstrates proficiency in fundamental C programming concepts including variable declaration, arithmetic operations, user input handling, and effective commenting practices. By mastering these foundational skills, a student can build more complex applications in the future. The learning process is substantially reinforced through the practice of coding rather than mere observation of theoretical concepts.
References
- Kochan, S. G. (2014). Programming in C (4th ed.). Indianapolis, IN: Developer's Library/Sams Publication.
- Perry, G. (2014). C Programming: Absolute Beginner's Guide (3rd ed.). Upper Saddle River, NJ: Pearson Education.
- Kernighan, B. W., & Ritchie, D. M. (1988). The C Programming Language (2nd ed.). Englewood Cliffs, NJ: Prentice Hall.
- ISO/IEC 9899:2011. (2011). Programming Languages – C. Geneva: International Organization for Standardization.
- GeeksforGeeks. (2021). C Programming Language. Retrieved from https://www.geeksforgeeks.org/c-programming-language/
- Tutorialspoint. (2021). C Language - Introduction. Retrieved from https://www.tutorialspoint.com/c_standard_library/c_index.htm
- W3Schools. (2021). C Tutorial. Retrieved from https://www.w3schools.in/c-tutorial/
- Learn-C.org. (2021). Learn C. Retrieved from https://www.learn-c.org/
- Harvard University. (2020). CS50: Introduction to Computer Science. Retrieved from https://cs50.harvard.edu/
- Microsoft. (2021). C Language Reference. Retrieved from https://docs.microsoft.com/en-us/cpp/c/c-reference?view=msvc-160