Docstoc

cs201

Document Sample
cs201 Powered By Docstoc
					Spring 2010_CS201_3 Idea Solution


/*This is idea only, make this assignment by yourself, best of luck"*/
#include <iostream>
#include <cstring>
using namespace std;
main(){
char Directory[16],part1[3],part2[4], part3[7];
char *Tptr;
int size;
cout<<"Enter the complete phone number (as \"0092-123-1234567\") :";
cin>>Directory;
Tptr=strtok(Directory, "-");
while(Tptr!=NULL ){
cout<<Tptr<<"\n";
size=strlen(Tptr);
switch(size){
case 4:
strcpy(part2, Tptr);
break;
case 3:
strcpy(part1, Tptr);
break;
case 7:
strcpy(part3, Tptr);
break;
}
Tptr=strtok(NULL,"-");
}
cout<<endl<<"Country Code is ="<<part2<<"\nCity code is ="<<part1<<"\n7-
digit number is = "<<part3<<"\nPhone number in correct sequence is
="<<part2<<"-"<<part1<<"-"<<part3;
system("Pause");}

//Best of Luck, change this assignment




/*Solution 2==This is idea only, make this assignment by yourself, best of luck"*/
#include <iostream>
#include <cstring>
#include <string.h>
#include <conio.h>
using namespace std;
main(){
char Directory[16],part1[3],part2[4], part3[7], *Tptr;
int size;
cout<<"Enter the complete phone number :";
cin>>Directory;
Tptr=strtok(Directory, "-");
do{
size=strlen(Tptr);
switch(size){
case 4:
strcpy(part2, Tptr);
break;
case 3:
strcpy(part1, Tptr);
break;
case 7:
strcpy(part3, Tptr);
break;
}
Tptr=strtok(NULL,"-");
}while(Tptr!=NULL );
cout<<endl<<"Country Code is ="<<part2<<"\nCity code is ="<<part1<<"\n7-
digit number is = "<<part3<<"\nPhone number in correct sequence is
="<<part2<<"-"<<part1<<"-"<<part3;
getch();}

				
DOCUMENT INFO
Shared By:
Categories:
Stats:
views:66
posted:5/14/2010
language:English
pages:2
Description: assignments solutions 14 may 2010