Lab Report: Lab 1
Objective: The objective of this lab was to become familiar with the Integrated
Development Environment (IDE) for C++ programming, modify and debug simple C++
programs, design and implement a struct, and submit the final code and results to the lab
instructor. This lab emphasized hands-on experience with the C++ development
environment, critical debugging skills, and the importance of using data structures to
manage related data more effectively.
Task 1: Familiarizing with the IDE
Approach:
• I began by downloading and installing Visual Studio, following the guidelines
provided by Microsoft.
• I created a new project in Visual Studio and entered the code from Gaddis's Program
8-6 (9th edition) to test the IDE's functionality.
• I placed a breakpoint at line 41 and stepped through the code, observing how the
IDE's debugging tools operate. This process allowed me to display two rows of
products on the screen.
Challenges: The main challenge was getting accustomed to the IDE's interface and
features, but after some exploration, I was able to efficiently navigate and use the tools
available.
Screenshots:
Task 2: Debugging
Approach:
I created a new project and added the provided code from Lab1_Task2.cpp. Upon
compiling and running the program, I identified several issues: incorrect division in
the output, incorrect values in the division, and an incorrect total of 0.
• Debugging Process:
o Incorrect Division: I noticed that the division output was not as expected
due to incorrect indexing and data manipulation in the nested loops. I
carefully reviewed the code logic and adjusted the loop variables and
calculations.
o Incorrect Values: The presence of a large negative number indicated a
memory or data corruption issue. I reviewed how the array was being
accessed and found that mismanaged variables could cause this issue.
Ensuring proper array indexing fixed this.
o Total Sales Calculation: The code to calculate the total sales was missing. I
added the code to the function and appropriate results were achieved
• After these adjustments, I recompiled and tested the program, ensuring all issues
were resolved.
Common Programmer Errors: The errors likely stemmed from a lack of attention to detail,
particularly with array indexing and loop management. These types of mistakes can be
avoided by carefully planning the code logic, regularly testing the code, and using
debugging tools to trace the flow of execution and data.
Screenshots:
Task 3: Implementing Structures
Approach:
• For this task, I reused the project from Task 1 and replaced the four separate arrays
(id, units, prices, sales) with a single product structure. The structure encapsulated
the data associated with each product, making the code more organized and easier
to maintain.
• I then modified the main function to use an array of product structures instead of
individual arrays. This required updating the function prototypes and definitions to
handle the product structure.
• After modifying the code, I tested it thoroughly to ensure that no new bugs were
introduced during the refactor.
Challenges: The main challenge was ensuring that all functions were properly updated to
use the product structure. This required careful attention to detail to avoid introducing new
bugs.
Bugs Encountered and Fixed: During the refactor, I initially forgot to update the function
signatures to reflect the new structure type. This led to compilation errors that were
resolved by carefully updating each function's parameters and implementation to use the
product structure correctly.
Screenshots:
Importance to Course and Career in CS/Engineering:
These objectives are integral to the course and a career in Computer Science or
Engineering because they lay the groundwork for more advanced programming concepts.
Mastery of an IDE and debugging techniques are essential for any developer, as these skills
directly impact the efficiency and accuracy of the code they produce. Moreover,
understanding and using data structures like structs is fundamental to problem-solving
and optimizing algorithms, which are key components of computer science and
engineering disciplines.
Being proficient in these areas not only makes one a more competent coder but also
prepares one for real-world software development, where writing, debugging, and
managing complex systems are everyday tasks. As we progress in our studies and
eventually transition into professional roles, the skills honed in this lab will be invaluable in
tackling more complex challenges in software development and engineering.
Conclusion: This lab was an excellent exercise in understanding the basics of C++
programming, including setting up an IDE, debugging, and using structures for data
management. The skills practiced in this lab are foundational and will be valuable as I
continue to develop more complex programs in future courses and in my career.