Yes! Found a debugger for Windows!
Publicado el 20 February 2012
Archivado en General | Salir del comentario
Bummer!!! I thought I had it right!
Publicado el 20 February 2012
Archivado en General | Salir del comentario
Note to self: when g++ compiles stuff, at least in what just happened, when there's an int divided by a double variable it results in an int variable. At least that's what happens here in Windows. It screwed up my Moore's Law source code. Bummer. Got check the g++ of Linux though. I really don't know if the compilers work exactly the same, but it seems pretty well like it.
Update: Yeah, it's the same stuff in Linux. I can still compile happily in Windows. I'm so glad that hasn't been taken away from me.
Update: Yeah, it's the same stuff in Linux. I can still compile happily in Windows. I'm so glad that hasn't been taken away from me.
Testing code for the Babylonian Algorithm
Publicado el 20 February 2012
Archivado en General | Salir del comentario
So, I searched in Google how to compute it in C++ and I found that I had to include a new source code called "cmath". I tried it and it worked. Here's the source code for testing the sqrt() function from the cmath source code:
Source Code:
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
long double number_to_calculate_square_root_of;
char ans;
cout << endl;
cout << "Greetings.\n";
do
{
cout << "Please enter the number you would like\n";
cout << "to calculate the square root of: ";
cin >> number_to_calculate_square_root_of;
cout << "The square root of that number is: " << sqrt(number_to_calculate_square_root_of) << ".\n";
cout << endl;
cout << "Would you like to repeate this process again?";
cout << "Press 'Y' for yes and 'N' for no:";
}while(ans == 'y' || ans == 'Y');
cout << endl;
cout << "Thank you for testing.";
return 0;
}
PS: I'm definitely going to use this for the Babylonian Algorithm just to check that the algorithm is actually approaching the square root of the inputted number.
PPS: My professor did mention this, but he told me he did...
Note to self: Pay MORE attention.
Batch File and Linux Script – Final Version
Publicado el 19 February 2012
Archivado en General | Salir del comentario
Batch File:
@echo off
echo Compiling and linking C++ source code,
echo and preparing the executable for debugging...
g++.exe -Wall -g -o executable SourceCode.cpp
echo Done
Linux Script:
echo "Compiling and linking C++ source code,"
echo "and preparing the executable for debugging..."
g++ -Wall -g -o executable SourceCode.cpp
echo "Done"PS: I really like their similarities. They are almost the same!
PPS: I got to remember to look for a debugger for the Windows OS later.
MinGW – The Solution! Windows Batch – Updated!
Publicado el 19 February 2012
Archivado en General | Salir del comentario
@echo off
echo "Compiling and linking C++ source code,"
echo "and preparing the executable for debugging..."
"C:\MinGW\bin\g++.exe" -Wall -g -o executable SourceCode.cpp
echo "Done"
PS: I can't believe it! No more jumping between operating systems! Now I'm just missing a debugger! I hate Emacs!
PSS: Before I totally forget. By installing MinGW in windows I had to add a new path for the environment variables. (In Windows 7 I can find that by clicking on Start > Right clicking on Computer > Properties > Advanced System Setting > Environment Variables. Then, once I found the "Path" variable, I had only to add a semi-colon at the end of the line ";" and add the desire path, which in this case was "C:\MinGW\bin". I did this because I had an error with libgmp-10.dll. The g++ from the MinGW directory could not find it when I tried to compile my source code. And now that I recall... setting that environment variable that allows me to run g++ directly through the command prompt window, without having to specify its directory. I should update this *.bat file once more.
Windows Batch File – Done!
Publicado el 19 February 2012
Archivado en General | Salir del comentario
@echo off
echo "Compiling and linking C++ source code..."
"C:\Dev-Cpp\bin\g++.exe" -o executable SourceCode.cpp
echo "Done"Note: It's basically the same stuff as in linux, the only difference is that I need to turn the echo off for the currently running codes. If I don't do this, the line "C:\Dev-Cpp\bin\g++.exe" -o executable SourceCode.cpp will show up in the command prompt window.
PS: It doesn't seem possible to prepare the executable for debugging in Windows. I just read something about MinGW, got to check it out... It's a pain to have to reboot every time I need to make programs.
I can compile in Windows!
Publicado el 19 February 2012
Archivado en General | Salir del comentario
Now I just need to make a script... I'm still too lazy to keep writing the same commands all over again in Windows.
Now that I remember…
Publicado el 15 February 2012
Archivado en General | Salir del comentario
Precision Error!
Publicado el 15 February 2012
Archivado en General | Salir del comentario
Here's the problem 1 of Lab #2:
A metric ton is 35,273.92 ounces.
1. Write a program that will read the weight of a package of breakfast cereal in ounces and output the weight in metric tons as well as the number of boxes needed to yield one metric ton of cereal.
2. Your program should allow the user to repeat this calculation as often as the user wishes.
And here's my "precision error" on the digits after the dot:
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2); The value weight_in_metric_tons is REALLY small if the value of package_of_breakfast_cereal_in_ounces is really small too. If this is the case, setting the precision to 2 will only fetch me the first two digits after the dot revealling 0.00 as the value for weight_in_metric_tons which is false. I should let the computer handle the precision in that calculation. I should test more numbers really close to zero though, to see if I get 0.000000000 (or something like that) as a result.
Note to self:
Practice more.
Script – Updated
Publicado el 10 February 2012
Archivado en General | Salir del comentario
rm SourceCode.o
rm executableecho "Compiling the C++ source code..."
g++ -Wall -c SourceCode.cpp
echo "Compilation done"
echo "Now linking..."
g++ -o Executable SourceCode.o
echo "Done"And here's the most compact version of the script:
rm executable
echo "Compiling, Linking and preparing the C++ source code for debugging..."
g++ -Wall -g -o executable SourceCode.cpp
echo "Done"Now the compiler compiles, links and prepares the C++ source code for debugging. There's no .o file create by the compiler using this last script. sige buscando »