Tushar Goel
What you want to do?
In the comments I have mentioned
Tushar Goel
Ok so let me explain the issue once more The above code works well in c But doesn't work well in c++ In c++ I am only able to print "p" and not "po" and "*po" Why so?
Anonymous
Ok so let me explain the issue once more The above code works well in c But doesn't work well in c++ In c++ I am only able to print "p" and not "po" and "*po" Why so?
This is not an EXPLANATION. 1- What do you mean by it is works on X but not Y? 2- What error did you get? i don't see any error: https://wandbox.org/permlink/JmYrCZKj1mrFnLEn
Tushar Goel
This is not an EXPLANATION. 1- What do you mean by it is works on X but not Y? 2- What error did you get? i don't see any error: https://wandbox.org/permlink/JmYrCZKj1mrFnLEn
No I didn't get any error I am saying, the c++ compiler doesn't print the value stored in "po" and in "*po"(derefrencing)
Tushar Goel
This is not an EXPLANATION. 1- What do you mean by it is works on X but not Y? 2- What error did you get? i don't see any error: https://wandbox.org/permlink/JmYrCZKj1mrFnLEn
So as you also tried printing the value in "po" and "*po" the compiler doesn't print the value.
Tushar Goel
Did you get me?
Anonymous
Did you get me?
Yeah, but i don't know the exact answer. Normally when you derefrencing a char* the compiler also interpreted it as a char and when passed through operator<<(std::ostream&, char*) it also try to print it as a ASCII code. So when you point to a int variable with a char* pointer, then you break the value interpretation.
Somaly
Hello guys I want to ask: for (int i = 0; i < 25; i++) { if (inReport[i].getName() == "") { break; } cout << inReport[i].getCusid() << endl; cout << setw(40) << displayPrice(inReport[i].getPur()) << endl; } cout << "End report"; cout << "\n"; I want to print out for those customer who has cusID but it prints out everything like for those who doesn’t have Cusid it’ll print space
Ankur
Can anyone help
Anonymous
Can anyone help
dont ask to ask, just ask
Ankur
I can't send media in here...
Anonymous
use a pastbin service to send your code, and give brief explanations..
𝙑𝙞𝙨𝙝𝙖𝙡
can anyone help solving a problem. Given an integer n we have to decompose this integer into all possible sum of distinct integers. for instance if n = 10 then the output should be 1+9 2+8 3+7 4+6 4+5+1 4+3+2+1
Ritu Raj
J[] begins at A008; what will be the address of J-2?
Prince Of Persia
Ritu Raj
If its char Result is A00A
It is A00A, as char is of only 8 bits?
Prince Of Persia
Yes
Ritu Raj
It should be A000
Ritu Raj
As subtraction of 8 from Hexa is A000
Prince Of Persia
🤨
Prince Of Persia
Addresses are on bytes
Anonymous
Hi guys. Am just a beginner in c++ language. Which framework is the best for creating GUI I also want to create a who want to be a millionaire software. Any recommendations
Anonymous
ImGui
Which ide can I use. Am using dev c++
Anonymous
1. Create a class named as car with data members as carcompany,cost of car,number of airbags. Create a file and write the array of objects into file. Search the data by carcompany from the stored file and display the result .
Anonymous
#include<iostream> #include<fstream> #include<string> using namespace std; class Car { private: string carCompany; float costCar; int numberAirbags; public: Car(){} Car(string carCompany,float costCar,int numberAirbags){ this->carCompany=carCompany; this->costCar=costCar; this->numberAirbags=numberAirbags; } string getCarCompany(){ return this->carCompany; } float getCostCar(){ return this->costCar; } int getNumberAirbags(){ return this->numberAirbags; } }; int main() { const string FILE_NAME="Cars.txt"; //Creating an array of objects of class Car Car cars[5]; cars[0]=Car("Audi",25000,4); cars[1]=Car("Ford",15000,2); cars[2]=Car("BMW",25400,2); cars[3]=Car("Honda",45604,4); cars[4]=Car("Fiat",14556,4); //write the array of objects into file. ofstream carsOfstream(FILE_NAME, ios::out); for(int i=0; i<5; ++i){ carsOfstream <<cars[i].getCarCompany() << " "<<cars[i].getCostCar()<< " "<< cars[i].getNumberAirbags()<< "\n"; } carsOfstream.close(); //read ifstream carsIfstream(FILE_NAME); if(!carsIfstream) { cerr << "Error: open file '"<<FILE_NAME<<"' for reading\n"; return 1; } string carCompany; float costCar; int numberAirbags; int counter=0; string line; //read from file while(carsIfstream>>carCompany>>costCar>>numberAirbags){ cars[counter]=Car(carCompany,costCar,numberAirbags); counter++; } carsIfstream.close(); //Search the data by carcompany from the stored file and display the result. string carcompanyTarget; int numbeOfCar=0; cout<<"Enter car company: "; getline(cin,carcompanyTarget); for(int i=0;i<5;i++) { if(cars[i].getCarCompany()==carcompanyTarget){ cout <<"Car company: "<<cars[i].getCarCompany() << ", Cost car: "<<cars[i].getCostCar()<< ", Number of airbags: "<< cars[i].getNumberAirbags()<< "\n"; numbeOfCar++; } } if(numbeOfCar==0){ cout<<"\nNot found\n\n"; } system("pause"); return 0; }
Anonymous
Is the programme correct to the question ❓
Anonymous
#include<iostream> #include<fstream> #include<string> using namespace std; class Car { private: string carCompany; float costCar; int numberAirbags; public: Car(){} Car(string carCompany,float costCar,int numberAirbags){ this->carCompany=carCompany; this->costCar=costCar; this->numberAirbags=numberAirbags; } string getCarCompany(){ return this->carCompany; } float getCostCar(){ return this->costCar; } int getNumberAirbags(){ return this->numberAirbags; } }; int main() { const string FILE_NAME="Cars.txt"; //Creating an array of objects of class Car Car cars[5]; cars[0]=Car("Audi",25000,4); cars[1]=Car("Ford",15000,2); cars[2]=Car("BMW",25400,2); cars[3]=Car("Honda",45604,4); cars[4]=Car("Fiat",14556,4); //write the array of objects into file. ofstream carsOfstream(FILE_NAME, ios::out); for(int i=0; i<5; ++i){ carsOfstream <<cars[i].getCarCompany() << " "<<cars[i].getCostCar()<< " "<< cars[i].getNumberAirbags()<< "\n"; } carsOfstream.close(); //read ifstream carsIfstream(FILE_NAME); if(!carsIfstream) { cerr << "Error: open file '"<<FILE_NAME<<"' for reading\n"; return 1; } string carCompany; float costCar; int numberAirbags; int counter=0; string line; //read from file while(carsIfstream>>carCompany>>costCar>>numberAirbags){ cars[counter]=Car(carCompany,costCar,numberAirbags); counter++; } carsIfstream.close(); //Search the data by carcompany from the stored file and display the result. string carcompanyTarget; int numbeOfCar=0; cout<<"Enter car company: "; getline(cin,carcompanyTarget); for(int i=0;i<5;i++) { if(cars[i].getCarCompany()==carcompanyTarget){ cout <<"Car company: "<<cars[i].getCarCompany() << ", Cost car: "<<cars[i].getCostCar()<< ", Number of airbags: "<< cars[i].getNumberAirbags()<< "\n"; numbeOfCar++; } } if(numbeOfCar==0){ cout<<"\nNot found\n\n"; } system("pause"); return 0; }
use a pastbin service
Anonymous
use a pastbin service
I'm getting error for the above program
Anonymous
Just fix it
What should I fix it?
Hermann
what is the difference between std::uint8_t and uint8_t?
Anonymous
if you do using namespace std; you don't need the std::
Hermann
the std namespace prefix
i can delcare uint8_t var1, without namespace std
Oleg
hi guys im junior in c, and i looking for good mentor for study C. where i can find mentors?! thanks
J
hi guys im junior in c, and i looking for good mentor for study C. where i can find mentors?! thanks
To look for a mentor, go into your room, lock the door, pick up a book online, stack up problems to solve up to 1000...put on your computer, then start learning and coding. Then you'll be surprised how you'll be of more benefit to yourself than a mentor
Otumian
To look for a mentor, go into your room, lock the door, pick up a book online, stack up problems to solve up to 1000...put on your computer, then start learning and coding. Then you'll be surprised how you'll be of more benefit to yourself than a mentor
A mentor doesn't have to teach you know. Books also do not have experience in C. In fact which book should one use as a guide. That's why you need a mentor to push and pull you
Anonymous
Hey
Anonymous
You have to write two programs to transform input array into output array. Part 1 Input Array :  2,4,8,5,12,15,6,10,7,30,25,43,46,45,21 Output Array :  2,4,8, 12, 6, 7, 43,46,21, 5,15,10,30,25,45   Part 2 Input Array :  2,4,8,5,12,15,6,10,7,30,25,43,46,45,21 Output Array :  2,4,8,21,12,46,6,43 ,7,30,25,10,15,45,5
Anonymous
Any one know this ansy
Anonymous
Please tell me
Anonymous
How
Suka
How
open your book about for loop and modulus. and try it first, discuss it here if you have any problem. goodluck
J
A mentor doesn't have to teach you know. Books also do not have experience in C. In fact which book should one use as a guide. That's why you need a mentor to push and pull you
Go ask Elon Musk who was his mentor that taught him how to program. Go ask Jeff Bezos who was his programming mentor, go ask Bill Gates who was his mentor while he coded games at a young age. Go ask Bjarne Stroustrup who was his mentor. Children of nowadays want everything at their plate. A mentor is not to pull and push you, your WHY should do that. A mentor is just to show you the steps to take, for example, go learn the fundamentals of c++ first, then code and code and code with that knowledge. Then come back and learn more advanced tips like abstraction, etc. You don't need a mentor for anything other than that. And this days of internet mentors are all in the internet offering their online class, so go join all and learn from all and see how each mentors solve the same tasks in different ways. Ask for pulling and pushing yourself, it's up to YOU
Anonymous
hi guys im junior in c, and i looking for good mentor for study C. where i can find mentors?! thanks
As others mentioned, you don't need a mentor. I suggest you read: Extreme C by Kamran Amini if you know the basics of C.
Hariyana Grande
if u wanted to change the original variable, u wud instead pass a pointer to it : void setValue(int *variable) { *variable = 650; // This will write 650 to the address where original variable resides } int main() { int variable = 326; setValue(&variable); // This will pass a copy of a pointer to where variable resides printf("Variable : %d\n",variable); // Will now print 650 :D }
Hariyana Grande
could anybody explain me the "setvalue(int *variable)" part?
Ammar
if u wanted to change the original variable, u wud instead pass a pointer to it : void setValue(int *variable) { *variable = 650; // This will write 650 to the address where original variable resides } int main() { int variable = 326; setValue(&variable); // This will pass a copy of a pointer to where variable resides printf("Variable : %d\n",variable); // Will now print 650 :D }
int variable = 326; in this case is a local variable, it resides on memory area called stack. &variable means the address of variable. So basically it's the address of stack. void setValue(int *variable); is a function that its first argument accepts a pointer to an integer. Pointer is simply just an address, you can read/write the value of memory from pointer by dereferencing it.
Ammar
i can delcare uint8_t var1, without namespace std
The namespace is just C++ style. There is no different behavior or size between std::uint8_t and uint8_t. They both are the same and interchangeably. If you #include the C header like <stdint.h> for example, it has typedef that defines uint8_t as unsigned char. So you can use uint8_t without namespace if you include that header.
Ammar
so those two variables one in main func and other in setvalue func are totally different from each other?
Yes they are different, but they have relation. On main function, it is where the variable actually stored. On setValue, it is just an address that points to the variable that is stored on the main's stack frame.
Hariyana Grande
ok got it thanks 👍
Hariyana Grande
im not from computer science so i dint know. much about ds algorithm
Hariyana Grande
Probably you should.
i will be happy if you suggest some books specially which explains pointers and arrays well
Hariyana Grande
loke in layman's term
Hariyana Grande
for non IT guy like me
Ammar
i will be happy if you suggest some books specially which explains pointers and arrays well
Unfortunately, I don't have any for this suggestion. Anyway, I loved to learn pointer from Assembly perspective (x86/x64). But probably it is not a good choice for everyone.
Ammar
Try this one @laugh https://www.teainside.org/rpx/21/27/b5/73/f1/Art%20Of%20Intel%20x86%20Assembly.pdf
Hariyana Grande
Lipman
will check out thanks 👍
MAC
will check out thanks 👍
There aren't books about C++ like Lipman
MAC
will check out thanks 👍
It's very difficult but depth explanation
Hariyana Grande
i will checkout thanks