Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
#pragma once
#include<string>
#include<iostream>
class Task1
{
public:
std::string First_Input()
{
std::string str1; // make a std::string to store string
std::cout << " Please type your First string here " << " : " << std::endl;
std::cin >> str1; // to use cin need to figure out input values type, in this case it is string, and in console screen users can input value. It is stored str1 in this case.
if (!(std::cin)) // if use wrong value(string) which is not match with string
{
std::cout << " That is not proper type of input " << std::endl;
std::cin.clear(); // clear the error flag so after it, it works correctly.
return First_Input(); // and use recursion untill users input proper type of value.
}
std::cout << "Your First Input is : " << std::endl;
std::cout << str1 << std::endl;
return str1;
}
std::string Second_Input()
{
std::string str2;
std::cout << "Please type your Second string here " << " : " << std::endl;
std::cin >> str2;
if (!(std::cin))
{
std::cout << " that is not proper type of input " << std::endl;
std::cin.clear();
return Second_Input();// also if users put not proper type of value, clear the cin and recursion.
}
std::cout << "Your Second Input is : " << std::endl;
std::cout << str2 << std::endl;
return str2;
}
std::string combine_inputs(std::string& str1, std::string& str2)
{
unsigned int start = 0;
std::string comebine_str;
for (unsigned int i = start; i < str1.length() || i < str2.length(); ++i) // For combined string, need to make new std::string.
{ // To print str1[0],str2[0],str1[1],str2[1],,,, need to put str1's index value in comebine_str[0]
if (i < str1.length()) // If put str1[0] into comebine_str[0], need to put str2's index value(str[0]) in combine_str[1]
{ // using for loop, put all str1 and str2's indexes in combine_str
std::cout << str1[i]; // i < str1.length() || i < str2.length() using || is important because
comebine_str += str1[i]; // if str1's string length is shorter than str2's length
} // The for loop end when i reached str1's last index so the rest of str2's indexes do not put into combine_str
if (i < str2.length())
{
std::cout << str2[i];
comebine_str += str2[i];
}
}
return comebine_str;
}
};