Longer Programs




Even long C++ programs are fairly easy to follow when you use whitespace and break long programs into a series of smaller functions. 

The sample program shown earlier is extremely simple. Some Visual C++ programs require several hundred thousand lines of code. Budding authors would not tackle a sequel to War and Peace; likewise, brand-new Visual C++ programmers should stay away from huge programming projects. Most of the programs you write for a while will be relatively small, maybe only 10 to 100 lines of code. 

Even a large program usually is not one big program stored in one file on the disk. Programmers often break up large programs into a set of smaller programs. The smaller programs work like building blocks, fitting together as needed to handle some kind of programming application. 

Just to give you another early view of a Visual C++ program, here is a program longer than the one you saw earlier. Don't sweat the specifics yet. Glance over the program and start getting used to the variety of special characters that Visual C++ understands. 

// Filename: 1STLONG.CPP  // Longer C++ program that demonstrates comments,  // variables, constants, and simple input/output  #include   void main()    {      int i, j;    // These three lines declare four variables      char c;      float x;      i = 4;       // i is assigned an integer literal      j = i + 7;   // j is assigned the result of a computation      c = 'A';     // Enclose all character literals                   // in single quotation marks      x = 9.087;   // x is a floating-point value      x = x * 12.3;// Overwrites what was in x                   // with something else      // Sends the values of the four variables to the screen      cout <<>

The next few lessons discuss the commands in this program in depth. Again, just to give you an idea of the importance of readability, here is the same program as seen by the Visual C++ compiler, but a very different program indeed to someone who must maintain it later: 

//Filename: 1STLONG.CPP//Longer C++ program that demonstrates  //comments, variables, constants, and simple input/output  #include   void main(){int i,j;//These three lines declare four variables  char c;float x;i=4;// i is assigned an integer literal  j=i+7;//j is assigned the result of a computation  c='A';//Enclose all character literals//in single quotation marks  x=9.087;//x is a floating-point value  x=x*12.3;//Overwrites what was in x with something else  //Sends the values of the four variables to the screen  cout<



Longer programs don't have to be harder to read than shorter ones.