1
0
This commit is contained in:
2025-10-10 02:17:07 +02:00
commit ee9f86004b
48 changed files with 2161 additions and 0 deletions

66
P2/smt4497-P2/Crono.cpp Normal file
View File

@@ -0,0 +1,66 @@
#include "Crono.h"
// agrupación de clases, funciones y variables globales
namespace ss {
Crono::Crono() // constructor
{
// Paso 1: Obtiene la frecuencia del timer del PC en tics/segundo usando QueryPerformanceFrequency
if (_ticsPorSegundoDelTimerDelPC < 0) {
// No se ha calculado la frecuencia aún. Se calcula ahora
LARGE_INTEGER frecuencia;
char _cadDbg[TAM_CADENA_DEBUG]; // snprintf almacena en una matriz intermedia y al pasar
// _cadDbg es un puntero a _cadDbg[0]
if (QueryPerformanceFrequency(&frecuencia)) {
_ticsPorSegundoDelTimerDelPC = frecuencia.QuadPart;
snprintf(_cadDbg, sizeof(_cadDbg), "La frecuencia del contador del PC es %d Hz\n",
_ticsPorSegundoDelTimerDelPC);
OutputDebugStringA(_cadDbg);
}
else {
OutputDebugStringA("Error al ejecutar QueryPerformanceFrequency en " __FUNCTION__);
}
}
}
Crono::~Crono() // destructor
{
}
bool Crono::Inicio()
{
bool res = false;
if (_ticsPorSegundoDelTimerDelPC > 0) {
// Paso 2: guarda el valor actual del timer del PC en tics usando QueryPerformanceCounter
LARGE_INTEGER ticks;
if (QueryPerformanceCounter(&ticks)) {
_ticsAntes = ticks.QuadPart;
res = true;
}
else {
OutputDebugStringA("Error al ejecutar QueryPerformanceCounter en " __FUNCTION__);
}
}
return res;
}
double Crono::Lee()
{
double segundos = -1.0;
// Paso 3: Obtiene el valor actual del timer del PC en tics usando QueryPerformanceCounter
LARGE_INTEGER ticks;
if (QueryPerformanceCounter(&ticks)) {
int64_t ahora = ticks.QuadPart;
segundos = (double)(ahora - _ticsAntes) / _ticsPorSegundoDelTimerDelPC;
}
else {
printf("Error al ejecutar QueryPerformanceCounter en " __FUNCTION__);
}
return segundos;
}
}

21
P2/smt4497-P2/Crono.h Normal file
View File

@@ -0,0 +1,21 @@
#pragma once
#include <stdint.h>
#include <stdio.h>
#include <stdarg.h>
#include <Windows.h>
namespace ss {
class Crono {
private: // por defecto todo es private
int64_t _ticsAntes = 0;
int64_t _ticsPorSegundoDelTimerDelPC = -1;
static const int TAM_CADENA_DEBUG = 64;
public:
Crono();
~Crono();
bool Inicio();
double Lee();
};
}

View File

@@ -0,0 +1,11 @@
#include "smt4497-P2.h"
int p2_classes()
{
ss::Crono crono;
crono.Inicio();
Sleep(10000);
double segs = crono.Lee();
printf("Segundos: %f\n", segs);
return 0;
}

View File

@@ -0,0 +1,34 @@
#include "smt4497-P2.h"
int p2_struct_union()
{
setlocale(LC_ALL, "spanish");
printf("\nEstructuras | PR<50>CTICA 2 | SS\n");
printf("---------------------------------\n");
struct {
int entero;
char car;
} vEstructura = { 256, 1 }; // Define + inicializa la estructura
union {
int entero;
unsigned char car[4];
} vUnion = { 256 }; // Define + inicializa la uni<6E>n
vUnion.entero = 0x89abcdef; // byte 0: 0xef, byte 1: 0xcd, byte 2: 0xab, byte 3: 0x89
printf("vUnion.entero vale 0x%x\n", vUnion.entero);
printf("El valor del byte 2 de vUnion.entero es: 0x%x\n",
// (vUnion.entero & 0x00ff0000) >> 16); tambi<62>n es v<>lido hacer primero la m<>scara y luego shift
(vUnion.entero >> (8 * 2) & 0xff));
printf("El valor del byte 2 de vUnion.entero es: 0x%x\n",
vUnion.car[2]);
// printf("Estructura: %d Tam: %d\n", vEstructura.entero, sizeof(vEstructura));
// printf("Union: %d Tam: %d\n", vUnion.entero, sizeof(vUnion));
return 0;
}

View File

@@ -0,0 +1,25 @@
#include "smt4497-P2.h"
typedef struct {
int entero;
char car;
} tEstructura_t;
tEstructura_t var1 = { 100, 1 };
tEstructura_t var2 = { 100, 1 };
int p2_typedef()
{
printf("\nEstructuras Personalizadas | PR<50>CTICA 2 | SS\n");
printf("------------------------------------------------\n");
tEstructura_t var3 = { 100, 1 };
int comparacion = memcmp(&var1, &var2, sizeof(tEstructura_t));
printf("resultado de comparar var1 y var2: %d\n", comparacion);
comparacion = memcmp(&var1, &var3, sizeof(tEstructura_t));
printf("resultado de comparar var1 y var3: %d\n", comparacion);
return 0;
}

View File

@@ -0,0 +1,12 @@
#include "smt4497-P2.h"
int main(int argc, char* argv[], char* envp[])
{
setlocale(LC_ALL, "Spanish");
// p2_struct_union();
// p2_typedef();
p2_classes();
return 0;
}

View File

@@ -0,0 +1,11 @@
#pragma once
#include <stdio.h>
#include <locale.h>
#include <Windows.h>
#include "Crono.h"
int p2_struct_union();
int p2_typedef();
int p2_crono();
int p2_classes();

View File

@@ -0,0 +1,143 @@
<?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>17.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{f2876c30-95c1-42d2-b434-6ce7ca561024}</ProjectGuid>
<RootNamespace>smt4497P2</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="Crono.cpp" />
<ClCompile Include="smt4497-P2-classes.cpp" />
<ClCompile Include="smt4497-P2.cpp" />
<ClCompile Include="smt4497-P2-struct-union.cpp" />
<ClCompile Include="smt4497-P2-typedef.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="Crono.h" />
<ClInclude Include="smt4497-P2.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Archivos de origen">
<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="Archivos de encabezado">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="Archivos de recursos">
<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="smt4497-P2.cpp">
<Filter>Archivos de origen</Filter>
</ClCompile>
<ClCompile Include="smt4497-P2-typedef.cpp">
<Filter>Archivos de origen</Filter>
</ClCompile>
<ClCompile Include="Crono.cpp">
<Filter>Archivos de origen</Filter>
</ClCompile>
<ClCompile Include="smt4497-P2-struct-union.cpp">
<Filter>Archivos de origen</Filter>
</ClCompile>
<ClCompile Include="smt4497-P2-classes.cpp">
<Filter>Archivos de origen</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="smt4497-P2.h">
<Filter>Archivos de encabezado</Filter>
</ClInclude>
<ClInclude Include="Crono.h">
<Filter>Archivos de encabezado</Filter>
</ClInclude>
</ItemGroup>
</Project>

View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
</Project>