Peace
what are the uses of pointer to derived class concept ?
Eyvaz
u mean how to use it?
Peace
but when we make pointer of Class A which points to object of Class B, that pointer cannot use any data member of class B. it can use member of Class A only as this pointer belongs to class A. so what's the use to pointer to derived class ?
Pavel
but when we make pointer of Class A which points to object of Class B, that pointer cannot use any data member of class B. it can use member of Class A only as this pointer belongs to class A. so what's the use to pointer to derived class ?
The idea is in using virtual functions with it, it is one of the ways (the most common in C++ I think) of implementing dynamic polymorphism. So let's say you have a message queue, you can create a base class of Message that have one virtual function process(), then you can create many different subclasses implementing this function differently, but you don't have to change the code that processes the queue when you add a new message type, because it works with the pointer of type Message to call process() on it.
Pavel
but when we make pointer of Class A which points to object of Class B, that pointer cannot use any data member of class B. it can use member of Class A only as this pointer belongs to class A. so what's the use to pointer to derived class ?
Also note that that's a common mistake of overusing this pattern by creating deep hierarchies of classes when rules for them become more complex (instead of dividing them), here are more details: https://en.wikipedia.org/wiki/Composition_over_inheritance
Anonymous
hi I program with c in linux distribution ubuntu I cried file type dat but when I compile program I can't see file
Où va le monde
MTProto is telegram transfer protocol, anyone knows, can i use it in my personal app?
Ludovic 'Archivist'
Type erasure also mixes well with concepts
Nana
Hello guys I need your help
Nana
pls help me with this question. I'm a beginner in c++
Nana
6. Vowels and Consonants Write a function that accepts a pointer to a C-string as its argument. The function should count the number of vowels appearing in the string and return that number. Write another function that accepts a pointer to a C-string as its argument. This func tion should count the number of consonants appearing in the string and return that number. Demonstrate these two functions in a program that performs the following steps: 1. The user is asked to enter a string. 2. The program displays the following menu: A) Count the number of vowels in the string B) Count the number of consonants in the string C) Count both the vowels and consonants in the string D) Enter another string E) Exit the program 3. The program performs the operation selected by the user and repeats until the user selects E to exit the program.
\Device\NUL
Hello guys I need your help
Read pinned message first and don porget to solve the capthca
Nana
Okay
Nana
#include <iostream> #include <cstring> #include <cctype> #include <cstdlib> using namespace std; void intro(); void menu(); char choice(); int count_vowels(char []); int count_consonants(char[], int); int main() { char user_choice; intro(); do { int LENGTH = 80; int total_vowels; int total_consonants; char c_string[LENGTH]; cout<<endl; cout<<"Enter a sentence: "; cin.getline(c_string, LENGTH); cout<<endl; menu(); user_choice = choice(); total_vowels = count_vowels(c_string); total_consonants = count_consonants(c_string, total_vowels); if(user_choice == 'A') { cout<<"You have chosen to count the number of vowels\n"; cout<<"The total vowels in that sentence is "<<total_vowels<<endl; } else if(user_choice == 'B') { cout<<"You have chosen to count the number of consonants\n"; cout<<"The total consonants in that sentence is "<<total_consonants<<endl; } else if(user_choice == 'C') { cout<<"You have chosen to count both vowels and consonants\n"; cout<<"The total vowels in that sentence is "<<total_vowels<<endl; cout<<"The total consonants in that sentence is "<<total_consonants<<endl; } else if(user_choice == 'D') { cout<<"Enter a string: "; cin.getline(c_string, LENGTH); cout<<endl; } else { cout<<"Good bye!\n"; exit(EXIT_SUCCESS); } }while(user_choice != 'E'); return 0; } void intro() { cout<<"This is a vowel and consonants program in C++\n"; cout<<"----------------------------------------------\n"; cout<<endl; } void menu() { cout<<endl; cout<<"Here are the menu: \n"; cout<<endl; cout<<"A) Count the number of vowels in the string\n"; cout<<"B) Count the number of consonants in the string\n"; cout<<"C) Count both the vowels and consonants in the string\n"; cout<<"D) Enter another string\n"; cout<<"E) Exit the program\n"; cout<<endl; } char choice() { char user_choice; cout<<"Enter your choice: "; user_choice = cin.get(); cin.ignore(); cout<<endl; return toupper(user_choice); } int count_vowels(char sentence[]) { int count = 0; int total = 0; while(*(sentence + count) != '\0') { if(tolower(sentence[count]) == 'a' || tolower(sentence[count]) == 'e' || tolower(sentence[count]) == 'i' || tolower(sentence[count]) == 'o' || tolower(sentence[count]) == 'u') total += 1; count += 1; } return total; } int count_consonants(char *sentence, int total_vowels) { int total_consonants = 0; int length = strlen(sentence); for(int count = 0; count < length; count++) { if(*(sentence + count) == ' ' || *(sentence + count) == '.' || *(sentence + count) == ',') length--; } total_consonants = length - total_vowels; return total_consonants; }
\Device\NUL
#include <iostream> #include <cstring> #include <cctype> #include <cstdlib> using namespace std; void intro(); void menu(); char choice(); int count_vowels(char []); int count_consonants(char[], int); int main() { char user_choice; intro(); do { int LENGTH = 80; int total_vowels; int total_consonants; char c_string[LENGTH]; cout<<endl; cout<<"Enter a sentence: "; cin.getline(c_string, LENGTH); cout<<endl; menu(); user_choice = choice(); total_vowels = count_vowels(c_string); total_consonants = count_consonants(c_string, total_vowels); if(user_choice == 'A') { cout<<"You have chosen to count the number of vowels\n"; cout<<"The total vowels in that sentence is "<<total_vowels<<endl; } else if(user_choice == 'B') { cout<<"You have chosen to count the number of consonants\n"; cout<<"The total consonants in that sentence is "<<total_consonants<<endl; } else if(user_choice == 'C') { cout<<"You have chosen to count both vowels and consonants\n"; cout<<"The total vowels in that sentence is "<<total_vowels<<endl; cout<<"The total consonants in that sentence is "<<total_consonants<<endl; } else if(user_choice == 'D') { cout<<"Enter a string: "; cin.getline(c_string, LENGTH); cout<<endl; } else { cout<<"Good bye!\n"; exit(EXIT_SUCCESS); } }while(user_choice != 'E'); return 0; } void intro() { cout<<"This is a vowel and consonants program in C++\n"; cout<<"----------------------------------------------\n"; cout<<endl; } void menu() { cout<<endl; cout<<"Here are the menu: \n"; cout<<endl; cout<<"A) Count the number of vowels in the string\n"; cout<<"B) Count the number of consonants in the string\n"; cout<<"C) Count both the vowels and consonants in the string\n"; cout<<"D) Enter another string\n"; cout<<"E) Exit the program\n"; cout<<endl; } char choice() { char user_choice; cout<<"Enter your choice: "; user_choice = cin.get(); cin.ignore(); cout<<endl; return toupper(user_choice); } int count_vowels(char sentence[]) { int count = 0; int total = 0; while(*(sentence + count) != '\0') { if(tolower(sentence[count]) == 'a' || tolower(sentence[count]) == 'e' || tolower(sentence[count]) == 'i' || tolower(sentence[count]) == 'o' || tolower(sentence[count]) == 'u') total += 1; count += 1; } return total; } int count_consonants(char *sentence, int total_vowels) { int total_consonants = 0; int length = strlen(sentence); for(int count = 0; count < length; count++) { if(*(sentence + count) == ' ' || *(sentence + count) == '.' || *(sentence + count) == ',') length--; } total_consonants = length - total_vowels; return total_consonants; }
Okay, why would you use VLA instead using MACRO const ?
Nana
pls what is VLA?
\Device\NUL
And, if you had many branching, use switch case
\Device\NUL
pls what is VLA?
Variable length Array
Nana
Okay
Nana
I've problem with d option in the menu
Nana
pls run it and help me
Nana
yes
\Device\NUL
yes
I see nothing wrong
Nana
first enter a string and then during the second iteration, choose the option d in the menu
Nana
it will appear a enter another sentence twice
Nana
pls how can I fix that?
\Device\NUL
it will appear a enter another sentence twice
Did you mean enter a string after enter a sentence ?
Nana
yes
Nana
it's suppose to be enter a sentence
Nana
when the option is chosen it repeats twice
Felix
Excuse me, how do we make a align center in C program? For example i have | | bracket that can fit 4 character, and when i fill 2 character i want it to align center, how can i do that?
\Device\NUL
when the option is chosen it repeats twice
Just make a variable to check if the branch go to D option
\Device\NUL
case 'D': strinput == 0;
Nana
case 'D': strinput == 0;
Hello pls it did not work. I tried continue statement it seems it works. if user_choice == 'D': continue;
\Device\NUL
yes
printf("|%s|", str) ?
Felix
i found a way to do it with 2 for loop but im wondering if i can do it with only a single for loop
\Device\NUL
I don't get the point tbh
\Device\NUL
pls try it and give me feedback
You get my point wrong, i mean use variable to check if the user go to the D input
\Device\NUL
if user has went to the D input skip string input
\Device\NUL
pls can you illustrate for me?
strinput = 0; do { if (strinput == 0) input_str; // bla-bla-bla if (option == 'D') strinput = 1; continue; } }
Nana
Okay
Nana
Thank you bro
Robby
Hello just joined!
Anonymous
Are there some material or paper for coroutine,
Anonymous
if else condition checks how many conditions???
Ravi
if else condition checks how many conditions???
if ... else if....else if....can be as many as you want if else checks only two conditions, though you can pass as many conditions in one if using &&
Ravi
little bit more explanation how does if else check two conditions
if(age>14 && age <20) cout adult else cout Dont Know
Ravi
2 conditions in one if,
Anonymous
2 conditions in one if,
then if statement can contain many conditions
Ravi
then if statement can contain many conditions
as many as you are able to write 😅
the Anupam
Hello I'm new in this fu**ing world
Anonymous
Hello guys Good evening I am electrical student semester three I have c++ and it is difficult to me I need tutors or expert to help me in excersise or assignment or project and he or she will be paid if he or she needs money for that Thanks
Anonymous
Pleas any one interested Let me know Or come private I really need some one who can know c++
Milwaukee
[19/11, 10:07 am] Kevin: Write a program to create a file called CallDataRecord and store the following information in the file “CellNumber, Date, StartTime, EndTime”. The program must display the information from the file on the console as following 0899011200, 31 October 2021, 08:00, 11:00 I have written a code but it has an error at the end but its running
Milwaukee
#include<iostream> #include<string> #include<fstream> using namespace std; ifstream fin; ofstream fout; int main() { fout.open("CallDataRecord.txt", ios::app); fout<<"0899011200, 31 October 2021,0800,1100"; fout.close(); cout<<"Message from the file is:\n"; fin.open("CallDataRecord.txt", ios::in); string msg; getline(fin, msg); fin>>msg; cout<<msg<<endl; system("PAUSE"); return 0;}
Milwaukee
Warning\Error sh:1:PAUSE:not found
\Device\NUL
I think PAUSE is specific to WIndows only
Milwaukee
OK lm running it on a mobile compiler
\Device\NUL
and Android is Linux
Sshadow
Hi guys, is this the right group for asking questions related to c++? I mean is this group active?
Madhavi
Hello
Madhavi
I have a question
Madhavi
I have function assume createrecord()
Madhavi
It there a way I can pass 2 different parameters with two different data structure
Madhavi
pause
Nope