#include<iostream>
using namespace std;
string swapDigitPairs(string s)
{
int len=s.length();//length of string
if(len%2==0) //if the length of string is even
{
for(int i=len-1;i>0;)
{
char a=s[i];
s[i]=s[i-1];
s[i-1]=a;
i-=2;
}
}
//if length of string is odd
else{
for(int i=len-1;i>0;)
{
char a=s[i];
s[i]=s[i-1];
s[i-1]=a;
i-=2;
}
}
return s;
}
int main()
{
string n;
cin>>n; //input the string
string old=swapDigitPairs(n);
cout<<"n - > "<<n<<" , old ->
"<<old<<endl;
return 0;
}
![Activities Code::Blocks IDE Tue 10:01 main.cpp [ar] - Code::Blocks 16.01 File Edit View Search Project Build Debug Tools Plug](http://img.homeworklib.com/questions/f3f66200-7fd9-11eb-9fc4-67aff19b213b.png?x-oss-process=image/resize,w_560)
![Activities Code::Blocks IDE- Tue 10:01 main.cpp [ar] - Code::Blocks 16.01 Search Project Build Debug Tools Plugins Settings H](http://img.homeworklib.com/questions/f46862a0-7fd9-11eb-b19f-1758e70cc88f.png?x-oss-process=image/resize,w_560)
![Activities XTerm Tue 10:02 main.cpp [ar] - Code::Blocks 16.01 File Edit View Search Project Build Debug Tools Plugins Setting](http://img.homeworklib.com/questions/f549eab0-7fd9-11eb-aa64-d1518d1f5e5a.png?x-oss-process=image/resize,w_560)
Question 2: Minmaxstring
#include<iostream>
using namespace std;
float minmaxstring(string s)
{
int ascii[122]={0};//create an array of 122 with 0 which denote the
ascii value
for(int i=0;i<s.length();i++)
{
ascii[int(s[i])]++;
}
//for finding min ascii value
float min=0;
for(int i=0;i<122;i++)
{
if(ascii[i]>=1)
{
min=i;
break; //when we find first ascii value grater than equal to 1 then
we break the loop and we have our min value
}
}
float max=0;
for(int i=122;i>0;i--)
{
if(ascii[i]>=1)
{
max=i;
break; //when we find first ascii value grater than equal to 1 then
we break the loop and we have our min value
}
}
return float(min/max); // return the ratio
}
int main()
{
string s;
cin>>s;
float ans=minmaxstring(s);
cout<<ans;
return 0;
}
![Activities XTerm Tue 10:16 main.cpp [ar] - Code::Blocks 16.01 File Edit View Search Project Build Debug Tools Plugins Setting](http://img.homeworklib.com/questions/f5bd1860-7fd9-11eb-bd1e-93c1a0a3a496.png?x-oss-process=image/resize,w_560)
can someone please help me solve these problem in c++ language and leave useful comments below...
Can you fix this program and run an output for me. I'm using C++ #include using namespace std; //function to calculate number of unique digit in a number and retun it int countUniqueDigit(int input) { int uniqueDigitCount = 0; int storeDigit = 0; int digit = 0; while (input > 0) { digit = 1 << (input % 10); if (!(storeDigit & digit)) { storeDigit |= digit; ...
I need this done in C++ Can someone help me get my code from crashing. The code compiles but it can be easily crashed with user input. The rubric and code below Instructions: Write a program that scores the following data about a soccer player in a structure: Player’s Name Player’s Number Points Scored by Player The program should keep an array of 12 of these structures. Each element is for a different player on a...
1. Implement a tostring() member function. This function will return a string representation of the LargeInteger. You should probably used string streams to implement this function. Note that the digits of the large integer are stored in reverse of their display order, e.g. the 1's place (100 ) is in index 0 of digits, the 10's place (101 ) is in index 1, etc. 2. Implement a second constructor for the LargeInteger. This constructor will be used to construct a...
C++ problem with dynamic arrays is that once the array is created using the new operator the size cannot be changed. For example, you might want to add or delete entries from the array similar to the behavior of a vector. This project asks you to create a class called DynamicStringArray that includes member functions that allow it to emulate the behavior of a vector of strings. The class should have: A private member variable called dynamicArray that references a...
C++ Can someone please help me with this problem- commenting each line of code so I can understand how to solve this problem using the C++ programming language? I really need help understanding how to create a file for the program to read. Do I create the file in Visual basic or create a text file? I have the code, just need to know how to create the file for it to read. #include<fstream> #include<iostream> using namespace std; int main()...
solve it in c++ 10
note:
please do not give me same answer like this
1. Define a Pet class that stores the pet's name, age, and weight. Add appropriate constructors, accessor functions, and mutator functions. Also define a function named getLifespan that returns a string with the value "unknown lifespan." Next, define a Dog class that is derived from Pet. The Dog class should have a private member variable named breed that stores the breed of the dog. Add...
HELP NEED!! Can some modified the program Below in C++ So that it can do what the Problem below asked it today???? #include <iostream> #include <stdlib.h> #include <string> #include <time.h> /* time */ #include <sstream> // for ostringstream using namespace std; // PlayingCard class class PlayingCard{ int numRank; int numSuit; string rank; string suit; public: PlayingCard(); PlayingCard(int numRank,int numSuit); void setRankString(); void setSuitString(); void setRank(int numRank); void setSuit(int numSuit); string getRank(); string getSuit(); int getRankNum(); int getSuitNum(); string getCard(); };...
C++ Object Oriented assignment Can you please check the program written below if it has appropriately fulfilled the instructions provided below. Please do the necessary change that this program may need. I am expecting to get a full credit for this assignment so put your effort to correct and help the program have the most efficient algorithm within the scope of the instruction given. INSTRUCTIONS Create a fraction class and add your Name to the name fraction and use this...
HELP NEED!! Can some modified the program Below in C++ So that it can do what the Problem below asked it today???? #include <iostream> #include <stdlib.h> #include <string> #include <time.h> /* time */ #include <sstream> // for ostringstream using namespace std; // PlayingCard class class PlayingCard{ int numRank; int numSuit; string rank; string suit; public: PlayingCard(); PlayingCard(int numRank,int numSuit); void setRankString(); void setSuitString(); void setRank(int numRank); void setSuit(int numSuit); string getRank(); string getSuit(); int getRankNum(); int getSuitNum(); string getCard(); };...
Help me solve this in C++ Rewrite the code to use array instead of linked lists. Please do not change anything besides the data structure. Instead of linked list use an array. The functionality should remain exactly the same. You can prepare a class if you wish but it is not required. /** * Queue implementation using linked list C style implementation ( no OOP). */ #include <cstdio> #include <cstdlib> #include <climits> #include <iostream> #define CAPACITY 100 // Queue max...