It is expected that all students will participate in the recitation during the regularly scheduled class. Those who participate elsewhere may not get the in-person assistance available during class.
Today's recitation will introduce the practice of multiple-file compilation, which will be used for the homework throughout the semester.
Start by accessing the Recitation Starter Files link on the ANGEL page and opening the folder named 1 which will be used for today's class.
What C++ source files are in that folder?
Points Earned: | 2.0/2.0 | |
Correct Answer(s): | There should be four C++ Source files (triarea.cpp, quadarea.cpp, heroarea,cpp, polyarea.cpp) |
NOTE: It is permissible to use other platforms to develop homework solutions, but today's class will assume Visual Studio, since that is in the classroom.
Be sure to read each group of instruction carefully before proceeding, so you do not have to spend valuable class time back-tracking to fix problems!
To create a new project in Visual Studio:
-- Open up the Visual Studio Package and then either Create a New Project from the welcome screen or from the File pull-down menu.
-- Request a C++ Win32 Console Application (not Visual Basic; not Win32 Project; not Empty Project)
-- At the bottom of the dialog box, assure that the new project will appear somewhere on the V drive and NOT the X drive.
How you organize your folders on that drive is up to you; if you have an X-drive folder already existing, you can move it to the V-drive.
-- On the second dialog box, be sure to modify Applications Settings to deactivate Precompiled Headers and make this an otherwise Empty Project
Once the project is created, right click on the Sources folder to Add New Item for each of the four given .cpp files (using the same file names is recommended). Also, install the given .h file into the Headers folder.
Once you have all of the files present, you may attempt to Build the Project.
What error arises when you try to do so?
Points Earned: | 2.0/2.0 | |
Correct Answer(s): | There will be multiple declarations for some of the functions in this program! |
The project should now Build correctly.
Take a look at triarea.cpp first. This contains a main function.
There really is very little in this file; it describes two triangles using arrays for vertices, and then computes their areas.
The actual computation is not visible here. Instead, near the top of the file is #include "triarea.h", which includes a little more information.
Go ahead and look at that file. Not much shows up there either.
But even without the implementation, there is enough information to compile the main function -- all it needs to know is what the parameter list is for triangleArea to call it properly. The details of the implementation are not required.
This is an important note about multiple-source file compilation. By implementing different features of a project separately, they can be thought about separately, and even implemented by different people.
Consider the project as it is now. How is this triangle area actually computed? (In which file does the function really appear?)
Points Earned: | 2.0/2.0 | |
Correct Answer(s): | This uses the calculation in polyarea.cpp. |
Now let us compute this area using a different function.
Right-click on polyarea.cpp to temporarily remove it from the project, and then right-click on the Sources folder to bring back heroarea.cpp.
Then try to compile and run the program.
Important note:
What changes had to be made to the triarea.cpp to use this other function?
Points Earned: | 2.0/2.0 | |
Correct Answer(s): | None! The interface, as defined in triarea.h, has been preserved. |
But this idea can also be used to share modules between unrelated projects.
Remove "triarea.cpp" from the Project and bring in "quadarea.cpp". This actually computes the area of a quadrilateral by imagining it to be the combination of two triangles.
What changes have to be made to "heroarea.cpp" to make it work with this new main function?
Points Earned: | 2.0/2.0 | |
Correct Answer(s): | Still, no changes should be required! |
I defined these arrays in this way so that I can still use the existing triangleArea function, which expects three-value arrays.
If you were to pass Xs as a parameter to that function, it would use only the first three elements (enough for a triangle).
But if you were to pass &Xs[2] as a parameter, that would use the address of the element Xw[2] as if it were the beginning of the array, and would use the last three elements of that array.
If we were to consider the two triangles described by the previous paragraphs, they should be two opposing parts of the quadrilateral.
A glance at the main function should discover that the second and third pairs of arrays actually describe the same figure -- they just start from a different vertex. Since it is the same figure, the areas should be the same. Are they?
Points Earned: | 2.0/2.0 | |
Correct Answer(s): | They are unequal. One is actually two large. |
In Visual Studio, you can set a breakpoint by clicking to the left of any program statement, which would make a Red dot appear in the margin.
Set a breakpoint on the return statement in quadArea.
Then from the Debug Menu, Start with Debugging to encounter that breakpoint. You should be able to observe the values of all the variables in your program by moving the cursor over them.
If you have variables for your triangle areas, it should be easy to see what values contributed to the incorrect area; and should also be able to determine what calculation would be required.
Also from the Debug menu, you can select Continue so you can find out what happened to the third calculation.
Take a look at the two triangle areas at this point in time, and the correct quadrilateral area (from the second figure).
What calculation would be required to give the correct answer from the two triangle areas in this situation?
Points Earned: | 2.0/2.0 | |
Correct Answer(s): | The correct answer is the difference of these two values; this is actually a concave figure, so both triangles include areas outside the quadrilateral. |
Fortunately, we have a function already present that would consistently give correct results.
Inside polyarea.cpp is a function called polyArea that would work for any size polygon (not just triangles). We just need to be able to use it.
Add the following line before the declaration of the main function:
extern double polyArea( const double[], const double[], int );.
Then use it in your main function instead of quadArea to compute the areas of both versions of this figure.
You will want to make sure that you have the correct files in your project when you test this!
Once it seems to work, place the function calls you used to compute your area in the Answer box for this question.
Points Earned: | 2.0/2.0 | |
Correct Answer(s): | Something like:
area1 = polyArea(Xs1, Ys1, 4); area2 = polyArea(Xs2, Ys2, 4); |
Does it matter here? Why or why not?
Points Earned: | 2.0/2.0 | |
Correct Answer(s): | Here it does not matter, since the first and last vertex are identical. There are only four distinct vertices in the array, so it is treated as a quadrilateral either way. |
It would have been possible to have that declaration appear automatically if it was inside the triarea.h file, but I chose not to do that.
Why would I resist placing that declaration in the header file?
(Consider this recitation as a whole).
Points Earned: | 2.0/2.0 | |
Correct Answer(s): | If we chose to use the heroarea.cpp for triangles instead of polyarea.cpp, then there would be a declaration for a non-existent function, which could interfere with compilation. |
相关推荐
C++单元测试三大框架的比较软件测试1、TUT结构框架简单。添加新的测试工作量小;无须注册测试;可移植性好(因其只需两个头文件,就可以完成测试工作);便于装卸;提供接口可以扩展其输出方式等。最大的优点:轻量级,...
c++test测试工具
C++实现检测USB鼠标的拔插 本文将详细介绍如何使用 C++ 实现检测 USB 鼠标的拔插,包括代码实现和相关技术要点的讨论。 一、检测 USB 鼠标的拔插的需求 在 Windows 环境下,检测 USB 鼠标的拔插是许多应用程序的...
太小可能导致网络开销占比过大,太大则可能影响网络的正常传输。 2. **测试时间**:长时间的测试可以提供更稳定的带宽估计,但也会增加测试的复杂性。 3. **误差控制**:网络环境的波动、系统负载等因素可能影响...
1. 熟悉C++ Test的自动化单元测试配置。 2. 使用“Generate Unit Tests”功能自动生成测试用例,并执行以查看测试结果。 3. 利用自定义测试用例向导创建新的测试用例,并检查执行结果。 4. 将数据源文件导入,根据...
openCV人脸检测的C++代码
根据提供的信息,我们可以总结出以下有关“C++小球碰撞”的相关知识点: ### C++小球碰撞概述 在计算机编程领域,“C++小球碰撞”通常指的是使用C++语言实现的小球之间的碰撞检测与响应机制。此类程序常用于游戏...
C++ Test实验(覆盖率测试) 在本实验中,我们使用 Parasoft C++ Test 工具来进行覆盖率测试和回归测试...1. Parasoft C++ Test 工具的使用指南 2. 覆盖率测试和回归测试的理论基础 3. 软件测试中的其他测试技术和方法
c++边缘检测代码。基于sobel算子的边缘检测
c++ 测试dll使用,用于java 调用c++ 测试 什么描述非得50字节 用于Java对接c++使用有需要的网友下载
Parasoft C++test 是经广泛证明的最佳实践集成解决方案,它能有效提高开发团队工作效率和软件质量。 C++test支持编码策略增强,静态分析,全面代码走查,单元与组件的 测试,为用户提供一个实用的方法来确保其C/C++...
行人检测C++代码
1. **窗口创建**:使用C++的图形库,如SFML、SDL或OpenGL,创建一个窗口来显示小球。这些库提供了窗口管理、图形绘制以及事件处理等功能。 2. **小球对象**:定义一个`Ball`类,包含小球的位置、速度、半径等属性。...
用C++实现的死锁检测与解除算法,代码很短,很简单。
是用C++编写的一个完整的小学生四则运算测试的课程设计,里面有源码和已经编译好的debug文件,debug文件中可以直接运行,测试的结果可以存放到txt文本框中,可以在程序中查看参见测试的结果。这个课程设计是一个优秀...
1. **图像预处理**:这是图像处理的第一步,通常包括灰度化、直方图均衡化、噪声去除(如高斯滤波或中值滤波)等步骤,目的是提高图像质量,便于后续分析。对于毛衣瑕疵检测,可能需要对图像进行平滑处理以减小纹理...
基于qt+c++实现ddos小工具可用于网站压测等性能测试+源码,适合期末大作业、课程设计、项目开发。项目源码已经过严格测试,可以放心参考并在此基础上延申使用~ 基于qt+c++实现ddos小工具可用于网站压测等性能测试+...
在C++编程中,检测端口是否被占用是网络编程中的常见需求,特别是在服务器开发或者客户端连接时,确保端口可用性至关重要。本教程将详细解释如何使用C++实现这一功能,主要涉及TCP协议和系统调用。 首先,我们要...
测试工具,有关测试C++ 具,通用测试C++工具测试C++工具测试C++工具
[1] 用户添加:增加一个用户到系统中。 [2] 用户登录:输入用户名和密码登录系统。 [3] 用户修改:修改用户信息。 [4] 用户删除:从系统中删除一个用户的所有信息。 [5] 城市添加:为用户增加一个城市,并输入(或从...