--Originally published at how not to program
Here is a code of do and do while
--Originally published at how not to program
Here is a code of how to use comments
#include <iostream>
using namespace std;
// Add a Double “//” then just type. The program will ignore the text after the “//”
int main()
{
cout << “Hello world!” << endl;
// No matter where in the code it is
/* you can also use “/*” to start a coment but you need to close it just like a parenthesis with “* /” */
return 0;
}
--Originally published at prgrm.co
In this WSQ, we had to calculate the value of e, to a desired lenght.
I watched this video that explains what e is.
#include <iostream>
#include <iomanip>
using
namespace
std;
int
main ()
{
int
A, B;
double
E, D;
for
(A=1; A<=15; A++ )
{
D=1;
for
(B=1; B<=A ; B++ )
{
D = D * B;
}
E = E + 1 / D;
}
cout<<setprecision(10)<<
"Estimated Value of e is "
<< E + 1 <<endl;
system
(
"pause"
);
--Originally published at how not to program
Here is a video of a nice show my buddy Rodrigo recomended to me. check it out
--Originally published at how not to program
Here is the final result of our final project. its about a code that gets the coordenates for a solid for you to graph it. I worked with Josue reyes and Rodrigo Zermeño
#include <iostream>
#include <fstream>
#include <cmath>
#define pi 3.14159
using namespace std;
char figura;
int HP, LP1, LP2, HC, RC;
float x, y, z;
int main(){
cout << “Que figura quieres (C=Cilindro/P=Prisma): “;
cin >> figura;
if((figura== ‘c’) || (figura== ‘C’)){
cout << “Ingresa la altura en milimetros (No mayor a 1000 mm): ” << endl;
cin >> HC;
cout << “Ingresa el radio en milimetros (No mayor a 1000 mm): ” << endl;
cin >> RC;
ofstream myfile;
myfile.open(“ArchivoCilindroProyecto.txt”);
myfile << “Las coordenadas del cilindro son: ” << endl;
for(z=0; z<=HC; z++){
for (int x=RC; x>=-RC; x–){
y=sqrt(pow(RC,2)-pow(x,2));
myfile << “(” << x << “,” << y << “,” << z << “)” << endl;
}
for (int x=RC-1; x>=-RC+1; x–){
y=sqrt(pow(RC,2)-pow(x,2));
myfile << “(” << x << “,-” << y << “,” << z << “)” << endl;
}
for (int y=RC; y>=-RC; y–){
x=sqrt(pow(RC,2)-pow(y,2));
myfile << “(” << x << “,” << y << “,” << z << “)” << endl;
}
for (int y=RC-1; y>=-RC+1; y–){
x=sqrt(pow(RC,2)-pow(y,2));
myfile << “(-” << x << “,” << y << “,” << z << “)” << endl;
}
}
}else if((figura== ‘p’) || (figura== ‘P’)) {
cout << “Ingresa la altura en milimetros (No mayor a 1000 mm): “;
cin >> HP;
cout << “Ingresa el lado 1 de la base en milimetros (No mayor a 1000 mm): “;
cin >> LP1;
cout << “Ingresa el lado 2 de la base en milimetros (No mayor a 1000 mm): “;
cin >> LP2;
ofstream myfile;
myfile.open(“ArchivoPrismaRectangularProyecto.txt”);
myfile << “Las coordenadas del Prisma
--Originally published at how not to program
Here is a code showing how to do a nested for
#include <iostream>
using namespace std;
int a;
int main()
{
cout << “For example ” << endl;
for (int x= 0 ; x <= 10;x++ ) {
cout << “Este es el ciclo numero ” << x << endl;
}
cout << “——————————————————————————–” << endl;
cout << “Nested For example ” << endl;
cout << ” ” << endl;
for (int z = 0 ; z >= 0 ; z– ) {
for (int y = 10; y >= 0 ; y–){
cout << “El ciclo for para la variable Z comienza en ” << y << endl;
}
}
return 0;
}
--Originally published at how not to program
Here is a little fuction that helps get factorials
#include <iostream>
using namespace std;
int main(){
int n, contador;
string respuesta;
cout << “Número Factorial ” << endl;
do
{
cout << “Dame un número positivo ” << endl;
cin >> n;
contador = n;
do
{
contador = contador – 1;
n = n * contador;
}while (contador != 1);
cout << “El factorial es: ” << n << endl;
cout << “¿Quieres probar otro número? ” << endl;
cin >> respuesta;
} while (respuesta == “si”);
cout << “Que tenga un buen día!! ” << endl;
return 0;
}
--Originally published at prgrm.co
Well, the semester is finally over, and what I can say about Ken’s teaching technique?
I enjoy the freedom to work at my rhythm and organize my duties and times as I see fit. The thing that I take with me from this course, apart from programming, is that. I need to start planning and organizing my time and work. Ken is an excellent teacher because most of my other teachers don’t really pay attention to this issue, most of the students are still learning how to organize their time and Ken knows it.
Excellent way of teaching because this is something I’ll take into my professional career.
--Originally published at prgrm.co
In this WSQ, we had to find the square root of a number using the Babylonian method.
Here is a video that explains what’s going on, and here is another video showing how another student programmed this.
Once I had this information I could start programming.
#include <iostream>
using namespace std;
long double square(long double X)
{
long double y=1, c;
for(int i=0; i<1000; i++)
{
c=X/y;
y=(y+c)/2;
}
return y;
}
int main()
{
int X;
cout << "Square Root... \n\nNumber: ";
cin >> N;
cout << "The square root of "<< N << " is equal to "<<square(X) << endl << endl;
return 0;
}
--Originally published at May The Code be With You
This time I’ll show you how to do the Quiz#9. Wich consist on getting the lenght of a Vector, Basically.
So, if you have basic knowloge on physics you may know how to get it. It is very simple due to the fact that the user gives you the coordenates of the two points in the cartesian plane. So, this is my code:
As I said, easy peasy lemon squeezy.