Answer to Question #11073 in C++ for rachel

Question #11073
using functions,solve the following in c++:
write a program that simulates a user typing a SMS on a mobile phone. in real life, to type 'a' the user presses 2 once, to type 'b' the user presses 2 twice, etc. to type 'j' user presses 5 once,to type 'l' the user presses 5 three times, ect.
your program should read a series of numbers and then generate the corresponding SMS and vise versa
what is the program?
1
Expert's answer
2012-06-22T08:38:17-0400
// SMS on a mobile phone.cpp : Defines the entry point for the console
application.
//

#include "stdafx.h"
#include
<iostream>
#include <conio.h>
#include
<string>

using namespace std;

int main()
{
string
inputseriesofnumbers="";
string outputmassage="";
int
positionletterinword=-1;
int countForletter[10];
for(int
i=0;i<11;i++){
countForletter[i]=0;
}
cout<<"1 2 abc
3 def\n";
cout<<"4 ghi 5 jkl 6 mno\n";
cout<<"7 pqrs 8
tuv 9 wxyz\n";
cout<<" * 0|_|
#\n";
cin>>inputseriesofnumbers;

do{
cout<<"Type a
series of numbers (* to exit and generate SMS ): ";

cin>>inputseriesofnumbers;
for(int
i=0;i<inputseriesofnumbers.length();i++){
switch(inputseriesofnumbers[i]){
case
'0':
countForletter[0]++;
break;
case
'1':
countForletter[1]++;
break;
case
'2':
countForletter[2]++;
break;
case
'3':
countForletter[3]++;
break;
case
'4':
countForletter[4]++;
break;
case
'5':
countForletter[5]++;
break;
case
'6':
countForletter[6]++;
break;
case
'7':
countForletter[7]++;
break;
case
'8':
countForletter[8]++;
break;
case
'9':
countForletter[9]++;
break;
}

}
}while(inputseriesofnumbers[0]!='*');

if(countForletter[2]==1){

outputmassage+="a";
}
if(countForletter[2]==2){

outputmassage+="b";
}
if(countForletter[2]==3){

outputmassage+="c";
}
if(countForletter[3]==1){

outputmassage+="d";
}
if(countForletter[3]==2){

outputmassage+="e";
}
if(countForletter[3]==3){

outputmassage+="f";
}
if(countForletter[4]==1){

outputmassage+="g";
}
if(countForletter[4]==2){

outputmassage+="h";
}
if(countForletter[4]==3){

outputmassage+="i";
}
if(countForletter[5]==1){

outputmassage+="j";
}
if(countForletter[5]==2){

outputmassage+="k";
}
if(countForletter[5]==3){

outputmassage+="l";
}
if(countForletter[6]==1){

outputmassage+="m";
}
if(countForletter[6]==2){

outputmassage+="n";
}
if(countForletter[6]==3){

outputmassage+="o";
}
if(countForletter[7]==1){

outputmassage+="p";
}
if(countForletter[7]==2){

outputmassage+="q";
}
if(countForletter[7]==3){

outputmassage+="r";
}
if(countForletter[7]==4){

outputmassage+="s";
}
if(countForletter[8]==1){

outputmassage+="t";
}
if(countForletter[8]==2){

outputmassage+="u";
}
if(countForletter[8]==3){

outputmassage+="v";
}
if(countForletter[9]==1){

outputmassage+="w";
}
if(countForletter[9]==2){

outputmassage+="x";
}
if(countForletter[9]==3){

outputmassage+="y";
}
if(countForletter[9]==4){

outputmassage+="z";
}
if(countForletter[0]==1){

outputmassage+=" ";
}
cout<<"Corresponding SMS is:
"<<outputmassage<<"\n";
cout<<"Press any key to
exit.";
getch();
return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS