#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;
}
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;
}
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; ...
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(); };...
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...
using C++ language!! please help me out with this homework In this exercise, you will have to create from scratch and utilize a class called Student1430. Student 1430 has 4 private member attributes: lastName (string) firstName (string) exams (an integer array of fixed size of 4) average (double) Student1430 also has the following member functions: 1. A default constructor, which sets firstName and lastName to empty strings, and all exams and average to 0. 2. A constructor with 3 parameters:...
Please help me to solve the problem with java language! An implementation of the Merge Sort algorithm. Modify the algorithm so that it splits the list into 3 sublists (instead of two). Each sublist should contain about n/3 items. The algorithm should sort each sublist recursively and merge the three sorted sublists. The traditional merge sort algorithm has an average and worst-case performance of O(n log2 n). What is the performance of the 3-way Merge Sort algorithm? Merge Sort algorithm...
In c++ programming, can you please edit this program to meet these requirements: The program that needs editing: #include <iostream> #include <fstream> #include <iomanip> using namespace std; int cal_avg(char* filenumbers, int n){ int a = 0; int number[100]; ifstream filein(filenumbers); if (!filein) { cout << "Please enter a a correct file to read in the numbers from"; } while (!filein.eof()) { filein >> number[a]; a++; } int total = number[0]; for (a = 0; a < n; a++) {...