diff options
| author | Musa Ahmed <[email protected]> | 2022-10-12 11:45:20 -0700 |
|---|---|---|
| committer | Musa Ahmed <[email protected]> | 2022-10-12 11:45:20 -0700 |
| commit | 30f694af6449574b630b1a5b36aa4d0896ddad55 (patch) | |
| tree | 6f7ecd26896e442f28137201fd2be17e5e845f16 /CST116-Ch7-Debugging-Ahmed | |
| parent | Answered questions & added text file (diff) | |
| download | cst116-ch7-debugging-m005a-30f694af6449574b630b1a5b36aa4d0896ddad55.tar.xz cst116-ch7-debugging-m005a-30f694af6449574b630b1a5b36aa4d0896ddad55.zip | |
Renamed & Added Flowchart
Diffstat (limited to 'CST116-Ch7-Debugging-Ahmed')
5 files changed, 311 insertions, 0 deletions
diff --git a/CST116-Ch7-Debugging-Ahmed/CST116-Ch7-Debugging-Ahmed.cpp b/CST116-Ch7-Debugging-Ahmed/CST116-Ch7-Debugging-Ahmed.cpp new file mode 100644 index 0000000..9563dba --- /dev/null +++ b/CST116-Ch7-Debugging-Ahmed/CST116-Ch7-Debugging-Ahmed.cpp @@ -0,0 +1,83 @@ +/******************************************************************** +* File: CST116-Ch7-Debugging.cpp +* +* General Instructions: Complete each step before proceeding to the +* next. +* +* Debugging Exercise 1 +* +* 1) Insert a breakpoint on the lines indicated in the code. +* 2) Run to Breakpoint 1. +* 3) When prompted, enter your age. +* 4) When the execution stops, add a watch on age and verify that +* the value in age is what you typed in. +* 5) Step over the if statement. +* 6) Why did the value in age change? +* In the if statement, the conditional was written as "age = 0" +* instead of "age == 1", thus the age is set to 1 everytime. +* 7) Fix the problem and repeat Steps 2 � 5 to verify the +* problem was corrected. +* 8) Stop debugging. +* +* Debugging Exercise 2 +* +* 1) Run to Breakpoint 1. +* 2) When prompted, enter the value 25 for your age. +* 3) Step over the if statement. Execution of the program should +* continue on the else if statement. +* 4) Verify that 25 is still stored in age. +* 5) Step over the else if. +* 6) Why is the program going to print "Teenager" for an age of 25? +* The else if statement was checking if the age was greater than +* or equal to 12 OR less than or equal to 19. Instead it should be +* checking if the age is between 12 AND 19 inclusively. +* 7) Fix the problem and repeat Steps 1 � 5 to verify the +* problem was corrected. +* 8) Stop debugging. +* 9) Remove Breakpoint1. +* +* Debugging Exercise 3 +* +* 1) Run the program without debugging. +* 2) When prompted, enter the value of 10 for your age. +* 3) Why does the program print both "Child" and "Adult"? +* There is a cout statement at the end of all the else if statements +* which is executing every time main is run. +* 4) Re-run the program this time with debugging and run to +* Breakpoint 2. +* 5) Why is the action with the else executing? +* The else statement has a semicolon at the end of it, so the statement +* is not included in the else statement and runs regardless of any conditions. +* Everytime main is executed, it will print adult at the end. +* 6) Fix the problem and re-run to verify the problem was corrected. +********************************************************************/ + +#include <iostream> +using std::cout; +using std::endl; +using std::cin; + +int main() +{ + int age = 0; + + cout << "Enter your age: "; + cin >> age; + + // Breakpoint 1 + // Put a breakpoint on the following line + if (age == 1) + cout << "First Birthday" << endl; + else if (age >= 12 && age <= 19) + cout << "Teenager" << endl; + else if (age < 12) + cout << "Child" << endl; + else if (age > 62) + cout << "Senior" << endl; + // Breakpoint 2 + // Put a breakpoint on the following line + else { + cout << "Adult" << endl; + } + return 0; +}
\ No newline at end of file diff --git a/CST116-Ch7-Debugging-Ahmed/CST116-Ch7-Debugging-Ahmed.sln b/CST116-Ch7-Debugging-Ahmed/CST116-Ch7-Debugging-Ahmed.sln new file mode 100644 index 0000000..8fed5aa --- /dev/null +++ b/CST116-Ch7-Debugging-Ahmed/CST116-Ch7-Debugging-Ahmed.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.3.32929.385 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CST116-Ch7-Debugging-Ahmed", "CST116-Ch7-Debugging-Ahmed.vcxproj", "{B0D44148-EC98-40C2-9B22-161D71C6254B}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {B0D44148-EC98-40C2-9B22-161D71C6254B}.Debug|x64.ActiveCfg = Debug|x64 + {B0D44148-EC98-40C2-9B22-161D71C6254B}.Debug|x64.Build.0 = Debug|x64 + {B0D44148-EC98-40C2-9B22-161D71C6254B}.Debug|x86.ActiveCfg = Debug|Win32 + {B0D44148-EC98-40C2-9B22-161D71C6254B}.Debug|x86.Build.0 = Debug|Win32 + {B0D44148-EC98-40C2-9B22-161D71C6254B}.Release|x64.ActiveCfg = Release|x64 + {B0D44148-EC98-40C2-9B22-161D71C6254B}.Release|x64.Build.0 = Release|x64 + {B0D44148-EC98-40C2-9B22-161D71C6254B}.Release|x86.ActiveCfg = Release|Win32 + {B0D44148-EC98-40C2-9B22-161D71C6254B}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {2D96A799-BBC3-412C-902D-33F28B360D22} + EndGlobalSection +EndGlobal diff --git a/CST116-Ch7-Debugging-Ahmed/CST116-Ch7-Debugging-Ahmed.txt b/CST116-Ch7-Debugging-Ahmed/CST116-Ch7-Debugging-Ahmed.txt new file mode 100644 index 0000000..94266c1 --- /dev/null +++ b/CST116-Ch7-Debugging-Ahmed/CST116-Ch7-Debugging-Ahmed.txt @@ -0,0 +1,24 @@ +FOR CHILD : + + Enter your age: 10 +Child + +C:\Users\macho\Source\Repos\cst116-ch7-debugging-M005A\CST116-Ch7-Debugging\x64\Debug\CST116-Ch7-Debugging.exe (process 18964) exited with code 0. + +FOR TEENAGER : +Enter your age: 15 +Teenager + +C:\Users\macho\Source\Repos\cst116-ch7-debugging-M005A\CST116-Ch7-Debugging\x64\Debug\CST116-Ch7-Debugging.exe (process 18828) exited with code 0. + +FOR ADULT : +Enter your age: 55 +Adult + +C:\Users\macho\Source\Repos\cst116-ch7-debugging-M005A\CST116-Ch7-Debugging\x64\Debug\CST116-Ch7-Debugging.exe (process 14928) exited with code 0. + +FOR SENIOR : +Enter your age: 65 +Senior + +C:\Users\macho\Source\Repos\cst116-ch7-debugging-M005A\CST116-Ch7-Debugging\x64\Debug\CST116-Ch7-Debugging.exe (process 5912) exited with code 0.
\ No newline at end of file diff --git a/CST116-Ch7-Debugging-Ahmed/CST116-Ch7-Debugging-Ahmed.vcxproj b/CST116-Ch7-Debugging-Ahmed/CST116-Ch7-Debugging-Ahmed.vcxproj new file mode 100644 index 0000000..1816c2b --- /dev/null +++ b/CST116-Ch7-Debugging-Ahmed/CST116-Ch7-Debugging-Ahmed.vcxproj @@ -0,0 +1,141 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <ItemGroup Label="ProjectConfigurations"> + <ProjectConfiguration Include="Debug|Win32"> + <Configuration>Debug</Configuration> + <Platform>Win32</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Release|Win32"> + <Configuration>Release</Configuration> + <Platform>Win32</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Debug|x64"> + <Configuration>Debug</Configuration> + <Platform>x64</Platform> + </ProjectConfiguration> + <ProjectConfiguration Include="Release|x64"> + <Configuration>Release</Configuration> + <Platform>x64</Platform> + </ProjectConfiguration> + </ItemGroup> + <PropertyGroup Label="Globals"> + <VCProjectVersion>16.0</VCProjectVersion> + <Keyword>Win32Proj</Keyword> + <ProjectGuid>{b0d44148-ec98-40c2-9b22-161d71c6254b}</ProjectGuid> + <RootNamespace>CST116Ch7Debugging</RootNamespace> + <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> + <ConfigurationType>Application</ConfigurationType> + <UseDebugLibraries>true</UseDebugLibraries> + <PlatformToolset>v143</PlatformToolset> + <CharacterSet>Unicode</CharacterSet> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> + <ConfigurationType>Application</ConfigurationType> + <UseDebugLibraries>false</UseDebugLibraries> + <PlatformToolset>v143</PlatformToolset> + <WholeProgramOptimization>true</WholeProgramOptimization> + <CharacterSet>Unicode</CharacterSet> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> + <ConfigurationType>Application</ConfigurationType> + <UseDebugLibraries>true</UseDebugLibraries> + <PlatformToolset>v143</PlatformToolset> + <CharacterSet>Unicode</CharacterSet> + </PropertyGroup> + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> + <ConfigurationType>Application</ConfigurationType> + <UseDebugLibraries>false</UseDebugLibraries> + <PlatformToolset>v143</PlatformToolset> + <WholeProgramOptimization>true</WholeProgramOptimization> + <CharacterSet>Unicode</CharacterSet> + </PropertyGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> + <ImportGroup Label="ExtensionSettings"> + </ImportGroup> + <ImportGroup Label="Shared"> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + </ImportGroup> + <PropertyGroup Label="UserMacros" /> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> + <ClCompile> + <WarningLevel>Level3</WarningLevel> + <SDLCheck>true</SDLCheck> + <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <ConformanceMode>true</ConformanceMode> + </ClCompile> + <Link> + <SubSystem>Console</SubSystem> + <GenerateDebugInformation>true</GenerateDebugInformation> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> + <ClCompile> + <WarningLevel>Level3</WarningLevel> + <FunctionLevelLinking>true</FunctionLevelLinking> + <IntrinsicFunctions>true</IntrinsicFunctions> + <SDLCheck>true</SDLCheck> + <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <ConformanceMode>true</ConformanceMode> + </ClCompile> + <Link> + <SubSystem>Console</SubSystem> + <EnableCOMDATFolding>true</EnableCOMDATFolding> + <OptimizeReferences>true</OptimizeReferences> + <GenerateDebugInformation>true</GenerateDebugInformation> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> + <ClCompile> + <WarningLevel>Level3</WarningLevel> + <SDLCheck>true</SDLCheck> + <PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <ConformanceMode>true</ConformanceMode> + </ClCompile> + <Link> + <SubSystem>Console</SubSystem> + <GenerateDebugInformation>true</GenerateDebugInformation> + </Link> + </ItemDefinitionGroup> + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> + <ClCompile> + <WarningLevel>Level3</WarningLevel> + <FunctionLevelLinking>true</FunctionLevelLinking> + <IntrinsicFunctions>true</IntrinsicFunctions> + <SDLCheck>true</SDLCheck> + <PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> + <ConformanceMode>true</ConformanceMode> + </ClCompile> + <Link> + <SubSystem>Console</SubSystem> + <EnableCOMDATFolding>true</EnableCOMDATFolding> + <OptimizeReferences>true</OptimizeReferences> + <GenerateDebugInformation>true</GenerateDebugInformation> + </Link> + </ItemDefinitionGroup> + <ItemGroup> + <ClCompile Include="CST116-Ch7-Debugging-Ahmed.cpp" /> + </ItemGroup> + <ItemGroup> + <Text Include="CST116-Ch7-Debugging-Ahmed.txt" /> + </ItemGroup> + <ItemGroup> + <Image Include="..\..\..\..\OneDrive\Pictures\CST116-Ch7-Debugging-Ahmed.png" /> + </ItemGroup> + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> + <ImportGroup Label="ExtensionTargets"> + </ImportGroup> +</Project>
\ No newline at end of file diff --git a/CST116-Ch7-Debugging-Ahmed/CST116-Ch7-Debugging-Ahmed.vcxproj.filters b/CST116-Ch7-Debugging-Ahmed/CST116-Ch7-Debugging-Ahmed.vcxproj.filters new file mode 100644 index 0000000..7670473 --- /dev/null +++ b/CST116-Ch7-Debugging-Ahmed/CST116-Ch7-Debugging-Ahmed.vcxproj.filters @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <ItemGroup> + <Filter Include="Source Files"> + <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier> + <Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions> + </Filter> + <Filter Include="Header Files"> + <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier> + <Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions> + </Filter> + <Filter Include="Resource Files"> + <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier> + <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions> + </Filter> + </ItemGroup> + <ItemGroup> + <ClCompile Include="CST116-Ch7-Debugging-Ahmed.cpp"> + <Filter>Source Files</Filter> + </ClCompile> + </ItemGroup> + <ItemGroup> + <Text Include="CST116-Ch7-Debugging-Ahmed.txt"> + <Filter>Source Files</Filter> + </Text> + </ItemGroup> + <ItemGroup> + <Image Include="..\..\..\..\OneDrive\Pictures\CST116-Ch7-Debugging-Ahmed.png"> + <Filter>Source Files</Filter> + </Image> + </ItemGroup> +</Project>
\ No newline at end of file |