This Program demonstrates the SWITCH…..CASE statement to perform different activities
#include <iostream.h>
#include <conio.h>
#include <ctype.h>
int main()
{
char cmd;
cout << "Chart desired: Pie Bar Scatter Line Three-D";
cout << "\nPress first letter of the chart you want: ";
cmd = toupper(getch());
cout << '\n';
switch (cmd)
{
case 'P': cout << "Doing pie chart\n"; break;
case 'B': cout << "Doing bar chart\n"; break;
case 'S': cout << "Doing scatter chart\n"; break;
case 'L': cout << "Doing line chart\n"; break;
case 'T': cout << "Doing 3-D chart\n"; break;
default : cout << "Invalid choice.\n";
}
return 0;
}
This Program performs the WHILE conditional statement with IF…ELSE conditional statement
#include <iostream.h>
int main()
{
int number= 1; // Number entered by user
int total = 0; // Total of numbers entered so far
int count = 0; // Count of numbers entered
cout << "\nEnter a number, 0 to quit:\n";
while (number != 0)
{
cin >> number; // Enter an integer only
if(number == 0)
cout << "Thank you. Ending routine.\n";
else count++;
total += number;
}
cout << "Total is " << total << '\n';
cout << "Count is " << count << '\n';
cout << "Average is " << total / count << '\n';
return 0;
}
This Program performs the DO…. WHILE conditional statement included with SWITCH….CASE statement#include <conio.h>
#include <ctype.h>
#include <iostream.h>
int main()
{
char cmd;
do {
cout << "Chart desired: Pie Bar Scatter Line Three-D Exit";
cout << "\nPress first letter of the chart you want: ";
cmd = toupper(getch());
cout << '\n';
switch (cmd)
{
case 'P': cout << "Doing pie chart\n"; break;
case 'B': cout << "Doing bar chart\n"; break;
case 'S': cout << "Doing scatter chart\n"; break;
case 'L': cout << "Doing line chart\n"; break;
case 'T': cout << "Doing 3-D chart\n"; break;
case 'E': break;
default : cout << "Invalid choice. Try again\n";
}
} while (cmd != 'E');
return 0;
}
This Program performs the FOR looping statement with IF conditional statement
#include <iostream.h>
int main()
{
int ascii_val;
for (ascii_val = 32; ascii_val < 256; ascii_val++)
{
cout << '\t' << (char)ascii_val;
if (ascii_val % 9 == 0)
cout << '\n';
}
return 0;
}
This Program performs the WHILE conditional statement to find out total of a number series
#include <iostream.h>
int main()
{
int number = 1, total = 0;
while (number < 11)
{
total += number;
number++;
}
cout << "\nTotal of numbers from 1 to 10 is " << total;
return 0;
}
#include <iostream.h>
#include <conio.h>
#include <ctype.h>
int main()
{
char cmd;
cout << "Chart desired: Pie Bar Scatter Line Three-D";
cout << "\nPress first letter of the chart you want: ";
cmd = toupper(getch());
cout << '\n';
switch (cmd)
{
case 'P': cout << "Doing pie chart\n"; break;
case 'B': cout << "Doing bar chart\n"; break;
case 'S': cout << "Doing scatter chart\n"; break;
case 'L': cout << "Doing line chart\n"; break;
case 'T': cout << "Doing 3-D chart\n"; break;
default : cout << "Invalid choice.\n";
}
return 0;
}
This Program performs the WHILE conditional statement with IF…ELSE conditional statement
#include <iostream.h>
int main()
{
int number= 1; // Number entered by user
int total = 0; // Total of numbers entered so far
int count = 0; // Count of numbers entered
cout << "\nEnter a number, 0 to quit:\n";
while (number != 0)
{
cin >> number; // Enter an integer only
if(number == 0)
cout << "Thank you. Ending routine.\n";
else count++;
total += number;
}
cout << "Total is " << total << '\n';
cout << "Count is " << count << '\n';
cout << "Average is " << total / count << '\n';
return 0;
}
This Program performs the DO…. WHILE conditional statement included with SWITCH….CASE statement#include <conio.h>
#include <ctype.h>
#include <iostream.h>
int main()
{
char cmd;
do {
cout << "Chart desired: Pie Bar Scatter Line Three-D Exit";
cout << "\nPress first letter of the chart you want: ";
cmd = toupper(getch());
cout << '\n';
switch (cmd)
{
case 'P': cout << "Doing pie chart\n"; break;
case 'B': cout << "Doing bar chart\n"; break;
case 'S': cout << "Doing scatter chart\n"; break;
case 'L': cout << "Doing line chart\n"; break;
case 'T': cout << "Doing 3-D chart\n"; break;
case 'E': break;
default : cout << "Invalid choice. Try again\n";
}
} while (cmd != 'E');
return 0;
}
This Program performs the FOR looping statement with IF conditional statement
#include <iostream.h>
int main()
{
int ascii_val;
for (ascii_val = 32; ascii_val < 256; ascii_val++)
{
cout << '\t' << (char)ascii_val;
if (ascii_val % 9 == 0)
cout << '\n';
}
return 0;
}
This Program performs the WHILE conditional statement to find out total of a number series
#include <iostream.h>
int main()
{
int number = 1, total = 0;
while (number < 11)
{
total += number;
number++;
}
cout << "\nTotal of numbers from 1 to 10 is " << total;
return 0;
}
No comments:
Post a Comment