You are on page 1of 2

INDEPENDENT UNIVERSITY, BANGLADESH

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING


SPRING 2021
CSC 101/ CSE 121
(Class Assessment: 4)
Marks: 20
Time: 35 minutes (Including the submission time 5 minutes)

Read the instructions carefully:


1. Plagiarism will not be tolerated.
2. Do not copy from any online source or from a person.
3. Partial marks will be given for partially solved questions.
4. Do not forget to fill up your name, id and section. Leave
score section blank.
5. You also should rename the quiz file with your id. For
example, the file name is “ID___ Class Assessment 3 Spring
2021” and suppose your id is 0000. You have to rename it as
“ID_0000_ Class Assessment 3 Spring 2020”. Unable to follow
this instruction may lead to invalid your quiz paper.

Name: Ashrafur Rahman Asem Id: 2021771 Sec:4 Score:

There are two strings s1 and s2 from the user input. Write a
program, which reverses these two strings and check whether
strings are equal or not (Take the help from
http://www.asciitable.com/). You should declare two functions
where one will do the reverse string and another one will
check whether s1 is exactly equal to string s2 or not.

Sample Input Sample Output


Enter first string: Rose Reverse of s1: esoR
Enter second string: Jack Reverse of S2:kcaJ
Strings are not equal
Enter first string: Mango Reverse of s1: ognaM
Enter second string: Mango Reverse of S2:ognaM

Strings are equal

You have to start your answer from here:

Ans: #include<bits/stdc++.h>//header file


using namespace std;
void strreverse(string s,string s1)//string reverse function
{
reverse(s.begin(),s.end());//the reverse function will reverse
the string by taking two parameters starting address and
ending address of the string
reverse(s1.begin(),s1.end());//the reverse function will
reverse the string by taking two parameters starting address
and ending address of the string
cout<<"Reverse of s1 is:"<<s<<endl<<"Reverse of s2
is:"<<s1<<endl;//printing string after reversed it
}
int checkEqualorNot(string s,string s1)//checking wheather the
string are equal or not if they are it will return 1 else it
will return 0
{
if(s==s1)
return 1;
return 0;
}
int main()//main method
{
string s,s1;//strings declaration
cout<<"Enter first string:"<<endl;
cin>>s;//inputting the string one
cout<<"Enter second string:"<<endl;
cin>>s1;//inputting the string two
strreverse(s,s1);//calling the string reverse function
if(checkEqualorNot(s,s1))//calling the chekEqualorNot function
if they are equal it will print they are equal else they are
not equal
{
cout<<"Strings are equal"<<endl;
}
else
cout<<"Strings are not equal"<<endl;
}

You might also like