\Device\NUL
I mean don't c and c++ also abstracts some concepts that should be known when writing code in assembly? Does that mean one should learn assembly before c?
Even C is derived from assembly, i think you should learn C first before learn assembly, it helps alot, unless you're masochist. I can confirm it, i just started to learn x86_64 assembly on linux and learning c make it easier.
A.M UMAR
#include <iostream> #include <string> using namespace std; class Cell_user{ protected: string user; int talkTime; public: Cell_user(string name, int time) : user(name), talkTime(time) {} int getTalkTime(){ return talkTime; } virtual void printBill() = 0; void talk(int time){ if(talkTime - time > 0){ talkTime -= time; } else{ talkTime = 0; } } }; class Postpaid: public Cell_user { public: Postpaid(string name, int time) :Cell_user(name, time) {} void printBill(){ //assuming the free fixed talktime is 30 float bill = 0; cout<<"Name: "<<user<<endl; if(talkTime > 30){ bill = (talkTime - 30) * 2.90; } cout<<"Type: Postpaid\n"; cout<<"Talktime: "<<talkTime<<endl; cout<<"Bill: "<<bill<<endl; } }; class Prepaid: public Cell_user { Prepaid(string name, int time) : Cell_user(name, time) {} }; int main(){ Postpaid Khaleed("Khaleed", 60); Khaleed.talk(2); cout<<"Time left: "<<Khaleed.getTalkTime()<<"\n\n"; Khaleed.printBill(); return O; }
A.M UMAR
Pls need help
Talula
Please which book
I had a single book, which was called https://www.cprogramming.com/books/ritchie.html
mito
void freeNodes(struct node *n) { struct node *temp; while(n != NULL) { temp = n; free(temp); n = n -> next; } free(temp); } Error : free(): double free detected in tcache 2 [1] 32680 abort (core dumped) ./new Am I getting this error because I have already freed temp ?
Prince Of Persia
thank you..
You're welcome
mito
You're welcome
I want to also ask one thing.. Do i actually have to free memory manually, or the OS will take care of it, when the program ends ?
Prince Of Persia
I want to also ask one thing.. Do i actually have to free memory manually, or the OS will take care of it, when the program ends ?
It's true that the memory will be freed when the programs ends But you have to free memory after you are done with that allocated memory Imagine you have allocated megabytes of memory If you don't delete that memory Your app will have a huge memory space for nothing
Prince Of Persia
What do you think about zombie child processes ? Does freeing memory manually works ?
I'm sorry but I have not so much information about zombie processes
Prince Of Persia
But I highly recommend to free memory no matter your program ends or not
Anonymous
I want to also ask one thing.. Do i actually have to free memory manually, or the OS will take care of it, when the program ends ?
In C++ there's no garbage collection so you have to manually free the memory when you are working in complex games and web apps. But in languages such as java , there's no need of it as system takes care all of it with predefined classes and also with Something known as Dynamic dispatch.
Anonymous
I want to also ask one thing.. Do i actually have to free memory manually, or the OS will take care of it, when the program ends ?
OS will take care of it when the program ends. This is practical for small programs. But some programs run for a long time, and some programs never even end, like those running on servers and stuff. There a memory leak can cause a ton of trouble.
mito
In C++ there's no garbage collection so you have to manually free the memory when you are working in complex games and web apps. But in languages such as java , there's no need of it as system takes care all of it with predefined classes and also with Something known as Dynamic dispatch.
I think I understand vaguely why i have to free memory manually .. It makes sense when I think about large games that have multiple maps.. where you don't want to load the whole game, but just parts of games whenever needed accordingly inside the same memory limit..
Abhishek
True.
Talula
but learning high level programming languages such as Java/Python/C++ as the first programming language has drawbacks - that you dont get to learn how things work behind the scenes. For example, what if i ask you to implement thread pool by yourself from scratch. Thats the reason one must start with C before attempting C++. High-level languages abstract the inner concepts.
Frankly it doesn't matter as long as you can get the job done... And you can't say Java/Python are similar to C++, Java complies to bitecode, while Python is interpreted... C++ is compiled and you need to know how memory works (as far as assigning is concerned)...
Jack ⁧3
𓆩 𓆪
Marcin
hello, does someone want to join to my project – simple client-server communicator? Project utilizes boost.asio for backend and Qt (QML) for frontend 😉 i've barely started this project – not much done yet
H.G
Hi I'm searching for project ideas dealing with OOP . Can anyone suggest me one?
Anonymous
make a class to maintain a school database
Parth
You will get plenty options
Anonymous
I don't understand what (×+=j-1) function does
Anonymous
It is really confusing 😕 me
Anonymous
Nils
Hey, what is wrong with this piece of code? const char sstr[] = "fuxey"; for (size_t it = 0; it != payloadLen; it++) { if (it > sizeof(sstr) && memcmp(payload + it, sstr, sizeof(sstr)) == 0) { printf("Replaced occurency at %zul\n", it); memcpy(payload + it, "hello world", sizeof(sstr)); } }
Nils
I want to replace all occurencies of "fuxey" with "hello world" (or at least the part of it that fits in).
Nils
However, it does not find occurencies
Nils
However, it does not find occurencies
Solved. It was searching for the null terminator too lol
Anonymous
What's wrong with this code? #include <iostream> using namespace std; int limitNumber; int sum=limitNumber;; int sumValue() void adding_a_series(int no) { if(no!=0) { sum=no+sum; adding_a_series(no-1); } } int main() { cout<<"Enter a limit number : "; cin>>limitNumber; adding_a_series(limitNumber); cout<<"sum= "<<sum<<endl; return 0; }
Anonymous
i have being trying to solve the codechef long challenge problem 4th..in div 3 ...but trying for 6 hr ...still getting TLE error
Anonymous
#include <bits/stdc++.h> using namespace std; int main() { int t; cin>>t; while(t--) { int n,k; cin>>n>>k; pair<int,int> p[n]; for(int i=0;i<n;i++) p[i]={i,i+1}; while(k--) {int s2=n/2; int z=0; for(int i=0;i<n;i++) {if(i%2!=0) { p[i].first=s2; s2++; }else { p[i].first=z; z++; } } sort(p,p+n); } for(int i=0;i<n;i++) cout<<p[i].second<<" "; cout<<endl; }return 0; }
Anonymous
i am unable to optimize my code ..if some one can help or give a method to optimize it ..plz tell
Anonymous
codechef - january long challlenge division 3 question 4: chef and riffles
Anonymous
can i share the link of the question
Talula
can i share the link of the question
If you wanna get banned, sure.
Anonymous
Hello where I can learn c++ and apply on hardware.?
Talula
why ?
Read the rules...
Zel
Read the rules...
We don't do home work, class work, certification tests, prize challenges, etc. People here are at their leisure to help you learn, not for you to profit off us.
Zel
That's what Tazz is telling you.
Aztec
We don't do home work, class work, certification tests, prize challenges, etc. People here are at their leisure to help you learn, not for you to profit off us.
One time i was in this situation then my message got reported as spam and now my telegram account is limited. I was simply trying to help an admin explain to someone here that we don’t solve homework here. Do be careful bro….
Abhishek
Apk
Pavel
How stupid sounds an idea to restrict ability to call specific functions by requiring an object as an argument that has no members, has private constructors, and has friend classes that can create this object, and you can't get these objects outside of some specific contexts (unless doing something very ugly)?
ㅤㅤㅤ
How to lower case a string without tolower function
\Device\NUL
How to lower case a string without tolower function
See ASCII Table and you will know how to lower case it
DEV 7
Neha wants to distribute packs of biscuits (Rs. 10 each) and some chocolates (Rs. 5 each) to nearby children living in her locality on her birthday. She has a total budget of Rs. N and she is allowed to buy at most X biscuits and Y chocolates. Calculate if she will be able to give all C numbers of children something under her budget.If so, print YES or else print NO for each testcases. Note - Child should get either one chocolate or one pack of biscuit.
DEV 7
We don't solve other's exams here.
it is not a exam problem its a book problem
Apk
it is not a exam problem its a book problem
Yeah and you just posted a book problem here without mentioning what efforts you put in it
Talula
Yes
You could use Arduino to learn about programming the hardware, it is best for new user.
Anonymous
Can someone assist me with codes for Date validation and include leap years
Anonymous
After Arduino which controller best for learn