Anonymous
Bruh please
Anonymous
I mean it
Hanz
wait 40 minutes
Anonymous
Okay sir
Anonymous
Thanks bruh
Anonymous
Chat c; For (c=0:c<=256;c++) { Printf("%c", c); } Output ?
Pavel
Anonymous
I know it's output.... I didn't mean that you have to run... It is to check yourself..... And what's problem with you? If you dont want to tell then ok leave it....there are 13731 people in this group
Anonymous
It's ok bro..... Well, This is infinite loop......
Pavel
I didn't get...
I mean it's your first message in the chat, you send some code and just one word "Output?". The first thing I can guess that you are doing some exam or homework and want to know what output of this program would be and too lazy to even describe what you want. Now after you described more I see that's not the case, my apology for not understanding you correctly.
Pavel
And it's not about you, just there are too many people that actually do that (send their assignments here)
Anonymous
Anonymous
Well, I'll post any question from now onwards.......
Anonymous
Have a great day...
Gakume
I have a question: There is a class which have a const variable called name, now I want to write both copy constructor and assignment operator for this class. What is the right way to handle the const variable? Since it should not be changed.
Gakume
Here is the full code if anyone wants to see. https://gist.github.com/incfex/3497539bbdf29b682087498adc41f20b
Gakume
For constructors, I did use initialiser list, but I am not sure about assignment operator one.
Anonymous
Suppose I wanna find if a no. exists in the array using hashmap. unordered_map<int, int> m; for (int i = 0; i < n; i++) { m.insert({ i, arr[i]}); } I'm getting the answer correct. Now my doubt: A key must be unique, but values may be more than one, right? So, the line m.insert({ i, arr[i]}); also works for m.insert({arr[i ], i);, thus the key-value mapping is different. Why's this working?
Pavel
Chat c; For (c=0:c<=256;c++) { Printf("%c", c); } Output ?
By the way, here's a more interesting riddle. This modification of your code will either print 128 characters and stop or will end up in infinity loop, depending on compiler and compiler flags. What is wrong with this code? #include <stdio.h> int main() { for (char c = 0; c <= 128; c++) { printf("%c", c); } }
Pavel
For constructors, I did use initialiser list, but I am not sure about assignment operator one.
If you have const members you can't change them from your assignment operator, you either need to leave them as is or if it will break the logic prohibit the assignment operator (so the outside code will need to create a new object each time)
olli
I have a question: There is a class which have a const variable called name, now I want to write both copy constructor and assignment operator for this class. What is the right way to handle the const variable? Since it should not be changed.
the copy constructor should be fairly straight forward - as you have it. In this case name is actually not constant, it's a pointer to a const char. While you cannot change the content what it is pointing to, you can change what it is pointing at. Using const char * const name; (const pointer to const char) would make sure you can change neither. If any member of a class is immutable you should reconsider whether it makes sense to support assignment operators, in this case I'd argue it would make sense to = delete them.
Gakume
btw, I was following the book "C++ Crash Course by Josh Lospinoso". It mentioned such requirements, maybe I misunderstand the requirements? See 4-5. below ``` EXERCISES 4-1. Create a struct TimerClass. In its constructor, record the current time in a field called timestamp (compare with the POSIX function gettimeofday). 4-2. In the destructor of TimerClass, record the current time and subtract the time at construction. This time is roughly the age of the timer. Print this value. 4-3. Implement a copy constructor and a copy assignment operator for TimerClass. The copies should share timestamp values. 4-4. Implement a move constructor and a move assignment operator for TimerClass. A moved-from TimerClass shouldn’t print any output to the console when it gets destructed. 4-5. Elaborate the TimerClass constructor to accept an additional const char* name parameter. When TimerClass is destructed and prints to stdout, include the name of the timer in the output. 4-6. Experiment with your TimerClass. Create a timer and move it into a function that performs some computationally intensive operation (for example, lots of math in a loop). Verify that your timer behaves as you expect. ```
Anonymous
By the way, here's a more interesting riddle. This modification of your code will either print 128 characters and stop or will end up in infinity loop, depending on compiler and compiler flags. What is wrong with this code? #include <stdio.h> int main() { for (char c = 0; c <= 128; c++) { printf("%c", c); } }
If the compiler give allocate 2 byte for chat then.... It should be infinite too... Because the range is -128 to 127....... Actually it'll go to -128 after c>127..... And then -128, -127, -126.... 0.....127 ... -128, -127....... It will keep rotate on these values
Pavel
If the compiler give allocate 2 byte for chat then.... It should be infinite too... Because the range is -128 to 127....... Actually it'll go to -128 after c>127..... And then -128, -127, -126.... 0.....127 ... -128, -127....... It will keep rotate on these values
The issue is, char, signed char and unsigned char are three different types. char can behave as signed or unsigned char (it's not specified) https://en.cppreference.com/w/c/language/type So in this case I should have specified whether I wanted signed or unsigned char, since it makes a difference here. Here's compiler flag difference example Unsigned: https://wandbox.org/permlink/HHAj0SZ2jLntun4f Signed: https://wandbox.org/permlink/5JqCFR5L5JfAt3XW I unfortunately couldn't find any online compilers that use char as unsigned char
Anonymous
I agree
Sam
/get cppbookguide
Jason
include Deck -> Deck will be holding 52 cards (cards came from Card class). include Player main() { Deck deck; Player user(deck) ; Player computer(deck); user.pick_cards(); -> here you show the user 5 random cards and ask if he is ok with them pick_computer_cards(); -> computer always pick 5 random cards user.show_cards(); -> reveal his 5 cards computer.show_cards(); -> reveal his 5 cards if user.get_points() > computer.get_points() -> calculates points and do the comparison { print "user win" } else if user.get_points() < computer.get_points() { print "computer win" } else { print "draw" } }
Jason
It is not running l need help
Anonymous
This message couldn't be displayed on your device due to copyright infringement.
Anonymous
??
Merit
Wap to.print the armstrong numbers between the numbers entered by user. Program must use a function to check whether given no is armstrong or not.
Hi everyone, I've create a vector pointers to my base class vector<Base*>test; (Base is an abstract class) I used this vector to push back the classes, which inherit from the base class test.push_back(new InheritedOne()); test.push_back(new InheritedTwo()); Is there a way i can add my abstract base class as well? Or any other different container or way to store my base class and inherited together?
佳辉
cant send picture at here?
Talula
cant send picture at here?
No... if you want to share the code, send pastebin link.
佳辉
Students find their own project based on criteria / scope of the project.The scope of the project to be carried out MUST BE using control structures AND Function: i. At least using MORE THAN TWO (2) Arithmetic Operations AND ii. Using Selection statement (if -else/switch case) AND iii. Looping Statement (while/do-while/for) AND iv. At least using ONE (1) function
佳辉
Any suggestion for the project?😭
佳辉
I think you should make Simple calculator
That project need write a problem statement,what should i write?
Anonymous
Hi Is there anyone teach low latency c++ programming ..
Talula
That project need write a problem statement,what should i write?
Solving the world problem in 1600s by making a calculator on modern PC.
佳辉
Solving the world problem in 1600s by making a calculator on modern PC.
So high lv,i still a newbie🥲only learned programming for 3month
Talula
So high lv,i still a newbie🥲only learned programming for 3month
Impressive title for a calculator... isn't it?
佳辉
Impressive title for a calculator... isn't it?
Problem analysis: • Input variables list • Output variables list • Process (formula and etc.)
佳辉
This part?i dont understand what i need to write...
Talula
This part?i dont understand what i need to write...
Which part? Input, output or process?
佳辉
What should i write actually?based on code?
Talula
What should i write actually?based on code?
Frankly calculator is input, output and process so it should be good... like add 2 numbers, subtract 2 numbers etc.
Gnostic Trades |
/getcbook
Stay Forward
/getcbook
佳辉
Frankly calculator is input, output and process so it should be good... like add 2 numbers, subtract 2 numbers etc.
Input: 5number,num1→num5 Process:Total=num1+num2+num3+num4+num5 Output:Display Total and average
佳辉
Something like this?
Code WHIZ
Code WHIZ
Simple amd easy as well
Rohan
Hii, Can I ask my doubts regarding a program in c language? I want to make an array which stores the address of each element of another array. But both the arrays should be created dynamically. Here is my code
Rohan
#include<stdio.h> #include<conio.h> #include<stdlib.h> int main() { int *a; int ar; int i,n; printf("How many"); scanf("%d",&n); a=(int*)malloc(sizeof(int)*n); *ar=(int*)malloc(sizeof(int)*n); printf("Enter %d numbers\n",n); for(i=0;i<n;i++) { scanf("%d",(a+i)); *(ar+i)=(a+i);//storing the address } printf("Traversing using pointer variable"); for(i=0;i<n;i++) { printf("Address of a[%d] is %d and value is %d\n",i,*(ar+i),(ar+i)); } printf("\n"); printf("Traversing using original array"); for(i=0;i<n;i++) { printf("Address of a[%d] is %d and value is %d\n",i,a+i,*(a+i)); } return 0; }
klimi
a=(int*)malloc(sizeof(int)*n); this looks weird
klimi
*ar=(int*)malloc(sizeof(int)*n); ani you are taking *ar from int... i dont think that is possible
tim
Well, I could work
tim
Because then you would store the memory location for the memory you just allocated somewhere in an int. It is however not guaranteed that this conversion works
tim
Plus: The place where you are writing to is also not allocated, so you would get a segmentation fault there