Pages

💡 Now You Can Get your Assignments Sollution here... .💡 100% plagiarism Free Service...💡 Responsibility, punctuality and on-time delivery... 💡 Furnishing you with experts... 💡 experienced in your subject 100% privacy... 💡 helping you with the highest efficiency , professionalism Affordable and budget-friendly costs that do not make a hole in your wallet

Showing posts with label Pattren. Show all posts
Showing posts with label Pattren. Show all posts

Telephone Digits The following program reads the letter codes A to Z and prints the corresponding telephone digit. This program uses a sentinel-controlled while loop. To stop the program, the user is prompted for the sentinel, which is #. This is also an example of a nested control structure, in which if. . .else, switch, and the while loop are nested.

//**********************************************************
// Program: Telephone Digits
// This is an example of a sentinel-controlled loop. This
// program converts uppercase letters to their corresponding
// telephone digits.
//**********************************************************

#include <iostream>
using namespace std;
int main()
{
char letter; //Line 1
cout << "Program to convert uppercase "
<< "letters to their corresponding "
<< "telephone digits." << endl; //Line 2
cout << "To stop the program enter #."
<< endl; //Line 3
cout << "Enter a letter: "; //Line 4
cin >> letter; //Line 5
cout << endl; //Line 6
while (letter != '#') //Line 7
{
cout << "The letter you entered is: "
<< letter << endl; //Line 8
cout << "The corresponding telephone "
<< "digit is: "; //Line 9
if (letter >= 'A' && letter <= 'Z') //Line 10
switch (letter) //Line 11
{
case 'A':
case 'B':
case 'C':
cout << 2 <<endl; //Line 12
break; //Line 13
case 'D':
case 'E':
case 'F':
cout << 3 << endl; //Line 14
break; //Line 15
case 'G':
case 'H':
case 'I':
cout << 4 << endl; //Line 16
break; //Line 17
case 'J':
case 'K':
case 'L':
cout << 5 << endl; //Line 18
break; //Line 19
case 'M':
case 'N':
case 'O':
cout << 6 << endl; //Line 20
break; //Line 21
case 'P':
case 'Q':
case 'R':
case 'S':
cout << 7 << endl; //Line 22
break; //Line 23
case 'T':
case 'U':
case 'V':
cout << 8 << endl; //Line 24
break; //Line 25
case 'W':
case 'X':
case 'Y':
case 'Z':
cout << 9 << endl; //Line 26
}
else //Line 27
cout << "Invalid input." << endl; //Line 28
cout << "\nEnter another uppercase "
<< "letter to find its "
<< "corresponding telephone digit."
<< endl; //Line 29
cout << "To stop the program enter #."
<< endl; //Line 30
cout << "Enter a letter: "; //Line 31
cin >> letter; //Line 32
cout << endl; //Line 33
}//end while
return 0;
}

C++ Code for Pattren

#include<iostream>
using namespace std;
void main()
{
int c=77,d=78,e=0;
for(int j=1;j<=24;j++)
{
for(char i=65;i<=c;i++)
{
cout<<i;
}
for(int i=1;i<=e;i++)
{
cout<<" ";
}
for(char i=d;i<=90;i++)
{
cout<<i;
}
d++;
c--;
e=e+2;
cout<<endl;
}
}
           Output:

C++ Code for Pattren

#include<iostream>
using namespace std;
void main()
{
int c=0;
for(int i=1;i<=5;i++)
{
for(int j=1;j<=5;j++)
{
if(j<=c)
cout<<" ";
if(j>c)
cout<<j;
}
cout<<endl;
c++;
}
}

1 2 3 4 5
   2 3 4 5
      3 4 5
         4 5
            5

C++ Code for Pattren

#include<iostream>
using namespace std;
void main()
{
int n=1,c=4,l=1;
for(int i=1;i<=4;i++)
{
for(int j=1;j<=c;j++)
{
cout<<" ";
}
for(int k=1;k<=n;k++)
{
cout<<l<<" ";
l++;
}
cout<<endl;
c--;
n++;
}
}

Output:
    1
   2 3
  4 5 6
7 8 9 10