Message from C, C++ discussions

December 2019

— 😊

— 

Char firstCapitalChar(char* str, int length, char putHereA){

if(str[length] == putHereA)return(str[length]);
else if(length == 0)return (char)0;
else if(putHereA == 'Z')return firstCapitalChar(str, length - 1, 'A');
else{

return firstCapitalChar(str, length, putHereA+1);
}
} this recursive function need to return me the first capital letter but it returning the last capital letter why?

— Maybe you need to pass the starting index and the last index of the string into your recursive function.... I made one and its working fine... Have a look
#include<bits/stdc++.h>
using namespace std;
char first_capital(string str,int start,int len)
{
if(start==len)
return str[len];
else if(str[start]>='A'&&str[start]<='Z')
return str[start];
else
return first_capital(str,start+1,len);
}
int main()
{
string str;
cin>>str;
cout<<"The first capital letter in the string is : "<<first_capital(str,0,str.length());
return 0;
}

Message permanent page

— As you need to get the first capital letter, so we need to check the character from the starting index, if found then return it, else increment the starting index... And the base condition would be that if the starting index becomes equal to the length of the string, then it will exit.

Message permanent page

— And we have assumed that there is a capital letter in the string that we pass

— Hi,I'm working on an exercise for the Classes, I created the class Matrix3D and I created the methods getdim and print.

Message permanent page

— And?

— Now I want to create a method sum, to sum 2 Matrixes(with the same dimensions) , the method must to do with pointers and must return a pointer, Matrix3D* sum(Matrix3D* m1, Matrix3D* m2) , but how can I select every element of m1 and m2 and put the sum in mat_sum?

Message permanent page

— Https://pastebin.com/A6w8fJUY this is the code that I wrote but I don't know what I should put in the FOR to select the elements,to sum and to put in mat_sum

Message permanent page

— Why are you using dynamic allocation for the sum

— I must return a pointer

— Matrix3D* mat_sum