Showing posts with label namespace. Show all posts
Showing posts with label namespace. Show all posts

Wednesday, March 15, 2017

C++ Part 25

Functions

  • Breaks code down into manageable chunks to write (and divide across development team)
  • Easier to debug – only one idea behind each module
  • Easier to maintain – buggy modules may be replaced without worrying about ramifications on other modules
  • Outsiders only need to know a module’s interface, not the details of its implementation.
  • Avoids duplication of code ⇒ more compact, and also easier to modify if code has bug  
  • Predefined functions: e.g., String.length(): String → Int  
  • Programmer-Defined functions: used similarly to predefined functions  

    This predefined functions need using namespace std;

Source : Absolute C++



Sunday, March 12, 2017

C++ Part 19

The switch statement is the only other kind of C++ statement that implements
multi way branches.


switch Statement

switch (Controlling_Expression)
{
case Constant_1:
Statement_Sequence_1
break;
case Constant_2:
Statement_Sequence_2
break;
.
.
.
case Constant_n:
Statement_Sequence_n
break;
default:
Default_Statement_Sequence
}


Example :
#include <iostream>

using namespace std;

int main()
{
   int vehicleClass;
double toll;
cout << "Enter vehicle class '1-3': ";
cin >> vehicleClass;
switch (vehicleClass)
{
case 1:
cout << "Passenger car.";
toll = 0.50;
break;
case 2:
cout << "Bus.";
toll = 1.50;
break;
case 3:
cout << "Truck.";
toll = 2.00;
break;
default:
cout << "Unknown vehicle class!";
}
/*

If you forget this break,
then passenger cars will
pay $1.50.
You need not place a break statement in
each case. If you omit a break, that case
continues until a break (or the end of the
switch statement) is reached. */


   return 0;
}

Digital Design Part 3

4th→ assembler translates it to the machine language. 1.6 [20] <§1.6> Consider two different implementations of the same instru...