Write C++ program that reads a string that has series of characters (maximum 10 characters), constituting therefore a meaningless string (i.e., the string does not have a meaning). Afterwards, the program asks the user several times the two characters he would like them to be swapped. To this purpose, the user has to specify the positions of these two characters. When the program stops, the user could end-up producing a meaningful string.
1
Expert's answer
2014-12-05T01:24:35-0500
#include<iostream.h> #include<string.h> #include<conio.h> #define MAX 1000 int main() { char *str=new char[MAX]; int i,f,s; cout<<"Input the string:"; cin.getline(str,MAX); char ans='Y',temp; while((ans=='Y')||(ans=='y')) { cout<<"first position:"; cin>>f; cout<<"second position:"; cin>>s; if((f<strlen(str))&&(s<strlen(str))) { temp=str[s]; str[s]=str[f]; str[f]=temp; } cout<<"You are want changeone more?"; cin>>ans; } cout<<"Result:"<<str; getch(); return 0; }
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
Finding a professional expert in "partial differential equations" in the advanced level is difficult.
You can find this expert in "Assignmentexpert.com" with confidence.
Exceptional experts! I appreciate your help. God bless you!
Comments
Leave a comment