vc++ standard by chandrapro


									Introduction to Microsoft Visual C++ 6.0. Coding standards. Short recap on C programming
language with an exercise.

1) Microsoft Visual C++ is an Integrated Development Environment that supports the development
of general purpose applications written using C/C++ programming languages. It has tools for
developing and debugging C++ code, especially that written for Windows API, DirectX API, but not
limitted to them. Visual C++ 6.0, which includes MFC 6.0, was released in 1998 and it was (and still
is) widely used for large and small projects1. More information on Microsoft Visual C++ Developer
Center (

The central element of Visual C++ is the project. Everything should be done inside a project.
Therefore, the first thing to construct is the project. A project is composed of:
   - a set of input files (source, header, resource and other types)
   - a set of settings (compiler settings, linker settings, resource builder settings, configuration
       settings etc.)
The project settings are also stored in a text file the project folder (with extension .dsp).

At a higher level, one or more projects are grouped together in a workspace. A workspace contains
one or more projects, out of which only one is the active project, i.e. the project that is currently
built and executed. It is a common practive to add in the same workspace projects linked to one
another, usually representing distinct modules of a large application composed of many
components/modules. The workspace settings are saved in a file with extension .dsw.

The students should be able to:
- Create a new, empty Win32 Console Application project
- Add new C++ source file to the project
- Browsing the project using File View and Class View
- Editing the C++ file
- Build (compile + link) the project
- Visualize and modify the project settings
- Execute the application
- Debug the application
- Re-open an existing project/workspace

2) Coding Standards (Programming Style)2 refers to a set of rules or guidelines used when writing
the source code for a computer program. It is often claimed that following a particular programming
style will help programmers quickly read and understand source code conforming to the style as
well as helping to avoid introducing faults. The most important rules refers to code indenting,
spacing, variables and functions naming, code blocks and comments. Below are given some

   a) indentation – Acceptable indentation styles:
   if (a < 5) {
        b = a;
        cout << a;

    if (a < 5)
         b = a;
         cout << a;

  There are however issues with this version under Windows XP, especially under the debugging
mode (ex: the values of static variables do not display). The debugging issues can be solved with a
patch called the "Visual C++ 6.0 Processor Pack".
      More      information      can      be      found,     for    instance,     on      Wikipedia
   b) naming – use self-explanatory variable and function names instead of short, criptic
        identifiers. For example,
   int countSpaces(char* str)
        int counter;
       // some computations…
       return counter;

       is more clear than, and is preferred over

   int cnt(char* str)
        int i;
       return i;

   c) Line length – don’t put more than 90 characters in one line of code.

The full set of coding standards for C++ programming language can be found on Wikipedia at the
following URL:
EXERCISE 1. Display a text file on the console.

#include <stdio.h>

int main(int argc, char* argv[]) {
        char ch;
        FILE* fp=fopen("test.txt", "r");

        if(fp==NULL) {
                printf(“Failed to open text file.\n”);
                return 0;

                printf("%c", ch);


        return 0;

EXERCISE 2. Count the occurrences of string “john doe” in a text file.

EXERCISE 3. Count the occurrences of words in a text file and display a synthesis of (word, word-
count) pairs.

To top