Search for question
Question

Guided Exploration 02: Introduction to C Code Purpose: Learn to use your development environment to edit and debug a C program that reads input and displays results. Use Git and

GitHub to version your code. Effort: Collaborate (Academic Integrity) Do not use Al tools such as ChatGTP except where indicated in the assignment. First try the assignment on your own and then connect with your group to discuss. Points: 20 (see rubric in canvas) Due Date: See Canvas Deliverables: Upload this document as a pdf or word document with your answers and upload your technical documentation as a word or pdf. Do not upload a zip file. Description Resources Part 1: Update Book Code Part 2: Debug Code Part 3: Update Code Part 4: Warnings and Errors Part 5: Version and Backup Updates Part 6: Explore Functions Description This first programming assignment is your opportunity to gain experience using an integrated development environment (IDE) to create, compile, debug and run a C program. When explaining, explain in your own words. You will be working with Chapter 2 fig02_01.c code from your repository. Remember to update your technical document. Resources Keep track of your resources that helped with this assignment from any of the following. Use the following resources before using other resources Lecture list Lecture number and slide numbers ● Book-list chapter and section ● C standard library - include URL If you needed more help understanding include Websites and videos - include URL Chatgpt - create URL to results Concept Resource Location - Lecture, book or URL Part 1: Update Book Code 1. Open up fig02_01.c from the chapter 2 example book code downloaded from Github for CS2060. Explain #include You can use Al tools to help you but make sure you include it in your resources. 2. Declare and initialize three integers called length, width and area. Explain what happens in memory when you declare a variable. Explain why it is important to initialize your variables in C. 3. Add code to a. print out "Enter the length" Explain the two different ways you could write secure code to print out a string. Include code. b. read the length into the variable length using scanf. Explain the function and arguments used to read in the length entered by the user. Include code with your explanation. Include What is the & doing? What does this mean is being passed? What does pass by reference mean? 4. Add code to a. print out "Enter the width" b. read the width into the variable width. 5. Add code to calculate the area and assign it to the area variable. 6. Print out the information: For example if 5 was entered for the length and 7 was entered for the width: "Length: 5 width: 7 and area is 35" Explain the function you used to print the length and width and the arguments you used. 7. Add correct return statement at end of main function Part 2: Debug Code You can use Al tools and other web resources to help you use your debugger and explore scanf but make sure you include the resources. Answer the questions in your own words. 1. Create a breakpoint at the line that prints out to enter the width. 2. Run program in debug mode 3. Set up debugging to watch length, width and area. 4. Step until you get to scanf to enter the length: 5 5. Step until you get to scanf to enter the width: 7 6. Step until you get to line to print the area. Take a screenshot showing what is stored in the variable. 7. 8. Continue stepping until the program ends. Run the program again. This time enter a letter for the length. What happens? Why do you think this happens? How might you implement code to avoid this? Hint: Explore what scanf returns. Create a variable to store the scanf return value. For example scanf Return = scanf(...) Take a screenshot showing what is stored in the scanfReturn value using your debugger. Put some code below that you tried to repeat if a valid integer is not entered. Do not worry if you weren't able to solve this problem but you should have something you tried. Part 3: Update Code 1. Update the code to find the average of the length and width that is entered. a. Create a double variable to store the average value of the length and width. b. Display the average value to one decimal place. What do you notice about the average result? What is the problem? How could it be fixed? 2. Try to fix this problem. Copy and paste your solution below. Part 4: Warnings and Errors It is important you understand where to go for your warnings and errors and use your IDE to help you improve your code. It is important you are running your code with the clang tidy analysis as that will help clean up your code. Part of your coding grades will include taking care of the warnings. In the past some students do not set up clang tidy and then their code doesn't run for us. As your projects get bigger this can cause many issues 1. Change the code so that an incorrect format specifier is used. Then take a screenshot of your warning. Put Screenshot here: 2. Make a change in the code that causes a syntax error. Run the code and take a screenshot of the error details. What did you do to cause the syntax error? Screenshot of syntax error: 3. Fix as many warnings as you can. Remember on Windows you are ignoring the annex k security warnings such as scanf_s and you should use scanf. Take a screenshot showing your warnings. Part 5: Version and Backup Updates Open up your GitHub Desktop. Commit and push your changes. Answer the following. You can use Al tools and other web resources to help you but make sure you include]the resources and answer in your own words. 1. What does it mean to commit your changes? 2. What does it mean to push your changes? 3. What does pull (you didn't use this yet, but if you work on multiple computers this can be helpful) do? 3. Put a screenshot that shows you now have two versions of fig02_01.c in your GitHub examples cloud repository Part 6: Explore Functions Create a function called calculateArea that has double parameters for the length and width and return the area as a double. From the main function pass the length and width (declared as integers) to the function and store the return value in the area variable that is declared in main as an integer. Print out the area in the function and print it out in main. Do not worry if you do not get everything working. Put your code here Did it work? Were there errors? Were there warnings? What is the benefit of using functions(methods) in your programs?