Showing posts with label Programming. Show all posts
Showing posts with label Programming. Show all posts

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;
}

Intro to C++ Part 12

  • How Do I Start a Program? 


  1.  Identify inputs and outputs.
  2. Understand what you asked for ( Ask Questions ).
  3. Break the program down. // Functions
  4. into steps, writing each step in pseudocode English.
  5.  Replace each pseudocode step with C++ codes.

Saturday, March 11, 2017

Intro to C++ Part 6

A Sample C++ Program  


##include <iostream>
using namespace std;The following line says that main is a function with no parameters that returns an int(integer) value:int main( )Some compilers will allow you to omit the int or replace it with void, which indicates
a function that does not return a value. However, the previous form is the most
universally accepted way to start the 
main function of a C++ program.
The program ends when the following statement is executed:
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...