Skip to main content

Posts

Showing posts from February, 2020

C programs QnA

Q. If sum of two integer is 14 and if one of them is 8 then find other integer. Ans: Well, this is very simple. Simply, one integer is 8 and sum of two integers is 14. So, we need to subtract the number 8 from their sum of 14 to get the second number. So, the second number is: 14 - 8 = 6 C-Program of this task Code---> #include<stdio.h> int main () { int num1 = 8 , num2 , sum = 14 ; num2 = sum - num1 ; printf ( "The second number is: %d" , num2 ); return 0 ; }

Checking two Strings equal or not and Concatenate two strings using Class in C++

In this C++ program we will Create a class ‘STRING’ which has one data member ‘str’. The class can perform concatenation of two string by ‘+’ operator overloading and check given two string are equal or not by ‘==’ operator overloading. Strings will be given by the user. input: Two Strings. output: Either the strings will be equal to each other or not and after that they will be concatenated. CODE----> #include<iostream> #include<string.h> using namespace std ; class STRING { private : char str [ 100 ]; public : void getString () { gets ( str ); } void display () { puts ( str ); } STRING operator +( STRING X ) { STRING s ; strcpy ( s . str , str ); strcat ( s . str , X . str ); return ( s ); } int operator ==( STRING X ) { if ( strcmp ( str , X . str )== 0 ) return 1 ; else return 0 ; } }; int main () { STRING s1 , s2 , s3 ; cout << "Enter 1st String: " ; s1 .