Friday, February 19, 2010

cmath v/s math.h

Here's a problem with pow() function in cmath and math.h:

With gcc set up, math.h just contains the the usual C function pow(double, double) - so all the functions work because with pow(int, int) both ints get promoted to double by compiler and all is OK.
cmath in more than a wrapper for math.h. First it includes math.h and then undefines a whole lot of stuff that math.h defined, and substitutes the c++ versions.
This includes the pow function declaration.
As the c++ overloaded functions (same as any other c++ compiler), you will get the ambiguity problem - when using pow(int, int).

P.S. - The ambiguity occurs with pow(int, int) because integers can be promoted to floats or doubles, which means that pow(int, int) can fit the so overloaded c++ pow function - so the compiler gets confused.

* * * * *

Thursday, February 11, 2010

How to make a good Website..

Answering the question "how" to make a Website is an easy task for many of us but the question which really puzzles us is "what" makes a good Website. We all visit many sites daily while surfing the net but there are a very few of them which leave an impression in our mind. Many sites are technically fine but fail on aesthetic grounds.

What makes a good WEBSITE:

Content:
The most important element of a website is its content. An interesting, informative and dynamic (updated frequently) content makes people visit the site again and again. The flashy colours or animated images look good at first but they never compell us to visit a site again and again. Only good content can do that.
Web is primarily a visual medium and its quite cumbersome to read text screen after screen. Try to keep the content to the point. Never elaborate.

Visuals:
Try not to Bold and Italicise the text too much, it gives an ameturish touch to your website. Sometimes underlined text get users confused with a hyperlink. Try avoiding it too. Make sure that the font size is even throughout. Do not wildly vary the size unless required.
Leave lots of blank spaces. Text on computer screens is hard to read, so don't cram up your text. Start lots of new paragraphs, and leave plenty of spaces between words and objects. Headings or horizontal rules are a good way to do this.
Do not use flashy colours as explained above. Try to select a good and readable combination of colour scheme. White text on black background may look classy but its difficult to read specially when text size is small.

Technicalities:
There are many things that make your web page look a bit different as what you expected:
  • Different browsers may show your web page differently. Try using a javascript available on net that kills this variation.
  • Sometimes web page view gets distorted on lower resolutions. Give a message on your website as "Website is best viewed in 1024X768" or anything like that.
  • The person viewing the web page may have certain settings different from yours.

Some tips:
  • To prevent your sites to look weird on text-only browsers you can add 'ALT' tags to ALL your images. If there is no alternative text that makes sense, use alt="" - this will help text-only browsers more than you will believe.
  • You can add a site search to your site. This will allow users to search your entire site easily and quickly.
  • Make sure that wherever your visitor is in your site, they can get to any other area. Also make sure they know where they are!!
As earlier said making a website is not a difficult task, it is designing and making people visit it again and again that makes it difficult. You need to make your website pretty different from all the other billions, floating on the internet.

* * * * *

Thursday, February 4, 2010

My way of writing a Quine

Here I m presenting a Quine written by me few days before. A Quine is a program that prints its own source code. In my source code user has an option of printing the source code n number of times.

Here is the code written in c:

#include < stdio.h >
int main()
{
int n;
char c;
FILE *f;
f=fopen(__FILE__,"r");
scanf("%d",&n);
while(n--)
{
while((c=getc(f))!=EOF)
putchar(c);
fseek(f,0,0);
}
return 0;
}



Here is the code written in c++:

#include <fstream>
#include<iostream>
#include <cstdio>
using namespace std;
int main()
{
int n;
string a;
cin>>n;
while(n--)
{
ifstream fin(__FILE__);
while(!fin.eof())
{
getline(fin,a,'\n');
cout<<a><<"\n";
}
}
return 0;
}