# How to display C++ code and math beautifully

#### Andy Nguyen

Just a note for the members who currently taking our online C++ course but it would be useful for many people as well.
• Code highlighter
Many people are used to [code]your code[/code] but you can use [code=csharp]your code here[/code] and paste the text code from some editor onto Quantnet. Here is how it will look using C++ language.
C++:
// Hello.cpp
//
// Simple example of function bodies.
//

// Preprocessor for include files
#include <stdio.h> // C style I/O
using namespace std; // The C++ logical collection of functions

void hello_C()
{
printf("Hello Quantnet, C style\n");
}

void hello_CPP()
{
cout << "Hello Quantnet, C++ style \n";
}
You can specify up to 201 languages such as csharp, java, sql, php, etc
• Latex
To display mathematical formula nicely on Quantnet, you can use $$latex-code$$
$$\large e^x=\sum_{n=0}^\infty\frac{x^n}{n!}$$ will give me $$\large e^x=\sum_{n=0}^\infty\frac{x^n}{n!}$$

#### Andy Nguyen

Just want to update that we now have full GeSHi support (201 programming languages) for coding posting on Quantnet. The default language will be C++.
To post code snippet and use a specific language, you can use code=csharp in this format

The full list of supported languages is here

SQL:
DROP TABLE IF EXISTS foo;
CREATE TABLE foo (
id INT(11) NOT NULL AUTO_INCREMENT,
characters INT(11) DEFAULT '0',
time_taken DOUBLE DEFAULT NULL,
language_used VARCHAR(100) DEFAULT NULL,
SOURCE text,
time_highlighted datetime DEFAULT NULL,
PRIMARY KEY  (id)
) TYPE=MyISAM;

C++:
/******************************************************

** Name:

** Filename: multiples.cpp

** Project #: Deitel & Deitel 1.32

** Project Description: Write a program that reads in two integers
and determines an prints if the first is a multiple of the second.

** Output:
First integer is a multiple of second integer
No
Yes
If Yes show that first number is  multiple of second
by displaying that first number divided by second number
is a whole number with no remainder

** Input:
Two integers

** Algorithm:
Explain function to be performed
direct user to input two integers
take the two integers that are input and
determine if the first integer divided by
the second integer will result in a whole
number with no remainder. If no remainder,
print Yes, first number is a multiple of second
number and explain. Then end program. If there
is a remainder print No, first number is not a
multiple of second number and explain.
Then end program.

******************************************************/

// Include files
#include <iostream>  // used for cin, cout
#include <conio.h>
using namespace std;

// Global Type Declarations

// Function Prototypes
void instruct (void);
void pause ();

//Global Variables - should not be used without good reason.

int main ()
{
// Declaration section
int integer1, integer2, answer, quotient, result;

// Executable section
instruct ();
cout << "Enter first integer: ";
cin >> integer1;
cout << "Enter second integer: ";
cin >> integer2;
quotient = integer1 / integer2;
result = quotient * integer2;
if ( answer == 0 )
cout << "\n**** Yes "<< integer1 << " is a multiple of "
<< integer2 << " ****" << endl;
if ( result == integer1 )
cout << "\nWe know "<< integer1 << " is a multiple of "
<< integer2 << " because " << integer1 << " divided by "
<< integer2 << " equals\na whole number which is "
<< quotient << " and " << quotient << " multiplied by "
<< integer2 << " equals " << result << endl;
if ( answer != 0 )
cout << "\n**** No "<< integer1 << " is not a multiple of "
<< integer2 << " **** "<< "\n\nWe know this because "
<< integer1 << " divided by "
<< integer2 << " equals " << quotient
<< " with a remainder of " << answer << endl;

pause ();
return 0;

}

void instruct (void)
{
// Declaration section

// Executable section
cout << "Enter two integers below. The program will then determine \n"
<< "if the first number entered is a multiple of the second \n"
<< "number entered.\n "<< endl;
}

void pause ()
{
// Declaration section

// Executable section
cout << "\nPress any key to continue...";
getch();
cout << "\r";
cout << "                            ";
cout << "\r";
}

Good stuff Andy.

#### JKPappas

##### GPUs-R-US
The syntax highlighting looks great, Andy.

For the LaTeX, why not use MathJax (http://www.mathjax.org/) instead? It might be a little lower-maintenance than running your own LaTeX image server, and they already have a MediaWiki theme available. Just a thought

#### Andy Nguyen

Someone mentioned mathjax the other day which I checked out but didn't get it to work on Quantnet. Nonetheless, I like to have total control of essential services we use here, Latex is one of them. I have our mathtex server running for several years without issues.

#### pruse

I've suggested this before... Writing math here would be a lot more fluid if it required typing only one character, like '\$'.

#### Prashant.Kumar

Love the cpp and Latex support!

I have a suggestion. Would it be possible to have line numbers visible? Maybe as a parameter option, like
C++:
[code=cpp, numbering=true]...
or maybe
C++:
[numbered_code=cpp]...
I could imagine it would be a nice feature to have for the C++ course. Then we could say things like, "Comment out line 4 and see if it compiles" or "delete lines 8-14, they aren't needed".[/code]

#### Andy Nguyen

Love the cpp and Latex support!

I have a suggestion. Would it be possible to have line visible
Done

#### Daniel Yang

hi Andy Nguyen and y'all, where can i find some Latex materials to learn? thanks

Replies
2
Views
853
Replies
0
Views
668
Replies
3
Views
1K
Replies
27
Views
4K
Replies
7
Views
36K