C++ Compiling Your First Code
These will be the fundamental examples for CFD
Example 1
// my first program in C++
#include <iostream>
int main() {
std::cout << "Welcome to the CFD Programming World!";
}
#include <iostream>
int main() {
std::cout << "Welcome to the CFD Programming World!";
}
Example 2
#include <iostream>
using namespace std;
const double R = 8.314;
const char newline = '\n';
int main ()
{
double MU=29.0; // Air Gas Constant
double Gas_Constant;
Gas_Constant = R/MU;
cout << Gas_Constant;
cout << newline;
}
using namespace std;
const double R = 8.314;
const char newline = '\n';
int main ()
{
double MU=29.0; // Air Gas Constant
double Gas_Constant;
Gas_Constant = R/MU;
cout << Gas_Constant;
cout << newline;
}
Example 3
// assignment operator
#include <iostream>
using namespace std;
int main ()
{
int dx, dy; // dx:?, dy:?
dx = 10; // dx:10, dy:?
dy = 4; // dx:10, dy:4
dx = dy; // dx:4, dy:4
dy= 7; // dx:4, dy:7
cout << "dx:";
cout << dx;
cout << " dy:";
cout << dy;
}
#include <iostream>
using namespace std;
int main ()
{
int dx, dy; // dx:?, dy:?
dx = 10; // dx:10, dy:?
dy = 4; // dx:10, dy:4
dx = dy; // dx:4, dy:4
dy= 7; // dx:4, dy:7
cout << "dx:";
cout << dx;
cout << " dy:";
cout << dy;
}
Example 4
#include <iostream>
using namespace std;
int main ()
{
double N;
double L;
double dx;
cout << "Please enter the number of grid points: ";
cin >> N;
cout << "The number of grid points you entered is " << N;
cout << " Please enter the Length Segment: ";
cin >> L;
cout << "The Length of the Segment you entered is " << L;
dx = L/N;
cout << " The discrete element size is " << dx;
}
using namespace std;
int main ()
{
double N;
double L;
double dx;
cout << "Please enter the number of grid points: ";
cin >> N;
cout << "The number of grid points you entered is " << N;
cout << " Please enter the Length Segment: ";
cin >> L;
cout << "The Length of the Segment you entered is " << L;
dx = L/N;
cout << " The discrete element size is " << dx;
}
Unless otherwise noted, all content on this site is @Copyright by Ahmed Al Makky 2012-2013 - http://cfd2012.com