Thursday, November 11, 2010

How to Disable Deprecation Warning on Visual Studio

Deprecation warnings can really be headache sometimes. But there are ways to disable it. Here I describe one.

To deprecation warnings you have to define _CRT_SECURE_NO_DEPRECATE as true before including any header file. An example code is attached below:

 1 /*******************************************************
 2 *  Problem Name:   Money in the bag
 3 *  Problem ID:    1002
 4 *  Occassion:    Offline Contest CSEDU Easy Volume
 5 *
 6 *  Algorithm:    
 7 *  Special Case:   
 8 *  Judge Status:   Accepted
 9 *  Author:     Saint Atique
10 *  Notes:     
11 *        
12 *******************************************************/
13 
14 #define _CRT_SECURE_NO_DEPRECATE 1
15 //#define _CRT_NONSTDC_NO_DEPRECATE 
16 
17 #include <iostream>
18 #include <cmath>
19 #include <cstring>
20 //#include <new>
21 #include <vector>
22 #include <queue>
23 #include <map>
24 #include <algorithm>
25 #include <iomanip>//for cout formatting
26 #define INF 2147483648
27 #define EPS 1e-8
28 using namespace std;
29 
30 int main() {
31  //freopen("..\\1002_in.txt", "r", stdin);
32  //freopen("..\\1002_out.txt", "w", stdout);
33 
34  double tk_amount[10] = {1000, 500, 100, 50, 20, 10, 5, 2, 1, 0.50};
35  double sum = 0;
36  int i, n;
37 
38  for (i=0; i<10; i++) {
39   cin>>n;
40   sum += n * tk_amount[i];
41  }
42 
43  cout.setf (ios::fixed, ios::floatfield);
44  cout.setf(ios::showpoint);
45  cout<<setprecision(2)<<sum<<" taka"<<endl;
46 
47  //fclose(stdin);
48  //fclose(stdout);
49  return 0;
50 }

How to Set Precision in C++

Programmers who use C++ for problem solving may need to set precision before printing floating numbers in standard output.

To display a floating number value of variable result with precision 2 (equivalent to .%2lf in scanf) use following code:
 1  cout.setf (ios::fixed, ios::floatfield);
 2  cout.setf(ios::showpoint);
 3  cout<<setprecision(2)<<result<<endl;

Here’s an example code used to solve a problem in easy volume section.

 1 /*******************************************************
 2 *  Problem Name:   Money in the bag
 3 *  Problem ID:    1002
 4 *  Occassion:    Offline Contest CSEDU Easy Volume
 5 *
 6 *  Algorithm:    
 7 *  Special Case:   
 8 *  Judge Status:   Accepted
 9 *  Author:     Saint Atique
10 *  Notes:     
11 *        
12 *******************************************************/
13 
14 #define _CRT_SECURE_NO_DEPRECATE 1
15 //#define _CRT_NONSTDC_NO_DEPRECATE 
16 
17 #include <iostream>
18 #include <cmath>
19 #include <cstring>
20 //#include <new>
21 #include <vector>
22 #include <queue>
23 #include <map>
24 #include <algorithm>
25 #include <iomanip>//for cout formatting
26 #define INF 2147483648
27 #define EPS 1e-8
28 using namespace std;
29 
30 int main() {
31  //freopen("..\\1002_in.txt", "r", stdin);
32  //freopen("..\\1002_out.txt", "w", stdout);
33 
34  double tk_amount[10] = {1000, 500, 100, 50, 20, 10, 5, 2, 1, 0.50};
35  double sum = 0;
36  int i, n;
37 
38  for (i=0; i<10; i++) {
39   cin>>n;
40   sum += n * tk_amount[i];
41  }
42 
43  cout.setf (ios::fixed, ios::floatfield);
44  cout.setf(ios::showpoint);
45  cout<<setprecision(2)<<sum<<" taka"<<endl;
46 
47  //fclose(stdin);
48  //fclose(stdout);
49  return 0;
50 }

Wednesday, November 10, 2010

How to change Document Root on WAMP

In this post we discuss how to change the www folder in apache based software wamp, which stands for Windows Apache, MySQL, PHP.

By default wamp’s www folder is C: \wamp\www. It means if you put a file on that folder for example test.html and enter address like this,
     http://localhost/test.html

on the browser it will fetch your test.html page.

To change the default www folder we need to change the configuration file of apache which is httpd.conf (httpd stands for http daemon). Follow the steps given below:

  • Browse to the directory C:\Program Files\wamp\bin\apache\Apache2.2.11\conf




  • Open the file using a text editor i.e. notepad or notepad++ etc.
  • Search for the text ‘DocumentRoot’. You will see a line like this in the search result:
              DocumentRoot "C:/wamp/www"

  • Edit this line to your preferred directory where your web page files are stored. For example, D:\web
              DocumentRoot "D:/web/"

  • Again search for text ‘<Directory’
    On the second result you will see a line like this one:
              <Directory "C:/wamp/www/">

    You will have to change this one too.
              <Directory "D:/web/">

  • Now clicking wamp icon on the system tray restart all services.

Changes will take into effect soon after you refresh localhost pages.