Anonymous
Even this works. struct ac { int ax; char bx; }; int main() { using A = ac; A B; B.~ac(); return 0; }
This is different. Here ac is a class and it has the destructor ~ac() provided by the compiler by default And B is just an object of this class.
Anonymous
It obviously needs an ostream parameter to know which output stream you want to print the object to. It returns the same ostream object by reference (because ostream objects cannot be copied) to support chaining. operator<< doesn't have to be a member of ostream because it doesn't have to access the internals of ostream class. It only needs to access the internals of the class that you are defining. If the operator<< were a member of ostream, then the class itself would be unbounded as it has to support any class type that can be defined at any point of the time in future. How would you define this method? If you think templates would be the solution, then there are 2 issues. 1. It is not possible to define a template method that can print any datatype because the template writer has no way of knowing what your datatype is and can't predict the internals of your class and can't access them either. 2. Templates can't be virtual. Only a class writer can decide how to print his class and not the ostream library writer. You overload operator<< for your class and make it a friend function so that it can access the internals. This method must be declared in the same namespace in which your class is defined. It will then be found by ADL.
I think I got it. Here we are not creating the operator<< function as a member of any class, it's a global function here. And global operator overloaded functions require both the members on either side of the operator to be passed as parameters, unlike operator overloading inside a class which only requires the member on the right side of the operator (left side being the class object itself). So, it's safe to assume ostream class has an operator<< template function that has only one template argument as a parameter, and it returns an instance of itself (*this, probably). But here, it requires two arguments, ostream& and Date & because this is a global function.
Anonymous
Anonymous
What would you call it then?
It is just a library type equivalent to any other class that you define. Built-in types are used to refer to only types like the arithmetic types, pointers, references and arrays.
Captain
Anonymous
We have to write it like <Class_object> << cout;
Ah yes, and the overloaded << function will receive ostream& as an argument and use it to display stuff. And I guess chaining wouldn't be possible in this case.
Anonymous
Anonymous
Anonymous
#Puzzle char a = 'a'; a.~char(); //Compiler Error using Char = char; //typedef char Char; char a = 'a'; a.~Char(); //Ok Why does C++ allow the latter but not the former?
something like an std::vector<> might contain either built-in types or custom class types. maybe this is allowed to reduce complexities arising in the destructors called using the allocators?
Anonymous
something like an std::vector<> might contain either built-in types or custom class types. maybe this is allowed to reduce complexities arising in the destructors called using the allocators?
Yes that is correct. The destructor for a built in type is no-op. There is nothing to be done in the destructor. So the compiler doesn't allow direct calls to the destructor for built in types. However destructor calls through typedefs are allowed to support templates because the template parameter is essentially an alias. So if you have a template class, struct or a union where you want to do your own memory allocations or need to call the destructor on a template dependent argument, you would essentially do something like a.~T(). If this code were to fail for built in types then you can't instantiate your template class or union with a built in type. So this was done to support this.
Rania
I have 2 array datasets in C++ and I tried to plot it. It turned out both datasets are forming linear line. What does it mean if arrays have linear relationship ? What can we infer ?
Rania
actually overlapping each other. rigt on the top.
Anonymous
I have 2 array datasets in C++ and I tried to plot it. It turned out both datasets are forming linear line. What does it mean if arrays have linear relationship ? What can we infer ?
What is in each array? When you plot it, did you use one array's elements as the x coordinates and the other array's elements as the y coordinates? How do you expect us to help you without giving us extra information?
Anonymous
x = [value1, value2... value-n] y = [value1, value2... value-n]
It just means that they are all points on the same line. That is all that you can infer.
Anonymous
this. i know.
There is nothing else to it
Rania
can we infer anyting else ? from this ?
Rania
cant send screenshot.
Anonymous
If I give you points (2,3), (3,4), (5,6) and (7,8) and you plot them, you will get a straight line. What additional info can you infer from them? At best you can find the equation of the line. In this case it happens to be y = x+1 You can't infer anything else.
Anonymous
mine doesn't have this relationship when being subtracted. Can I share my data here ?
No. Not all linear relationships satisfy the subtraction property (wrt to x and y coordinates) that my dataset had. For ex if the equation of the line were y = 2x + 3, some sample points on the line would be (1,5), (2,7), (3,9). (5-1) != (7-2) != (9-3)
Anonymous
Actually can I PM you ?
This question is not related to C++ anymore. So find a group appropriate for this and ask your questions there. But you will get the same answer I gave you.
Anonymous
You seriously have so much time on your hand... lol I envy you.
I don't get into fights in the OT group. Saves some of my time 😁
mayway
I'm not getting output..can anyone help me
mayway
Topic: bubble sort
mayway
Anyone??
olli
Topic: bubble sort
where is your source?
Njabu
Anyone with code or program that demonstrate Abstraction in C++ or notes about Interfaces and Abstraction in C++ *Please send here*
Psalmbonga
Lab Assignment #1: Creating an Invoice Class Lab Objectives In this lab, you are required to: ▪ Write the pseudo code. ▪ Create a class definition. ▪ Declare data members. ▪ Define a constructor. ▪ Define set and get functions. ▪ Write an application to demonstrate the capabilities of class Invoice. ▪ Compile and execute the program. ▪ Compare your output with the sample output provided. ▪ Submit your lab assignment for assessment on Moodle. ▪ Submit as: (a) as a zipped folder (use link named lab assignment 1(CODE)) (b) as a PDF(use the link named lab assignment 1 (PDF)). Description of the Problem Create a class called Invoice that a hardware store might use to represent an invoice for an item sold at the store. An Invoice should include four pieces of information as data members—a part number (type string), a part description (type string), a quantity of the item being purchased (type int) and a price per item (int). [Note: Use numbers that contain decimal points (e.g., 2.75)—called floating-point values—to represent rand amounts.] Your class should have a constructor that initializes the four data members. Provide a set and a get method for each data member. In addition, provide a member function named getInvoiceAmount that calculates the invoice amount (i.e., multiplies the quantity by the price per item), then returns the amount as an int value. If the quantity is not positive, it should be set to 0. If the price per item is not positive, it should be set to 0. Write a test program that demonstrates class Invoice’s capabilities. It is important to validate your input. Hints: ▪ To solve this exercise, revisit your previous solutions. ▪ The input values for the quantity and the price per item must be validated before they can be used to set the corresponding data members. ✓ This should be done both in the constructor and in the appropriate set functions.▪ The function header for getInvoiceAmount should be int getInvoiceAmount (). ▪ Be sure to follow consistent programming conventions. Sample Output: Part number: 12345 Description: Hammer Quantity: 100 Price per item: R5 Invoice amount: R500 Quantity cannot be negative. Quantity set to 0. Invoice data members modified. Part number: 123456 Description: Saw Quantity: 0 Price per item: R10 Invoice amount: R0
Psalmbonga
I need help with this 👆
Psalmbonga
Here's my code👇
Psalmbonga
#include <iostream> #include "Invoice.h" using namespace std; // function main begins program execution int main() { // create an Invoice object Invoice invoice( "12345", "Hammer", 100, 5 ); // display the invoice data members and calculate the amount cout << "Part number: " << invoice.getPartNumber() << endl; cout << "Part description: " << invoice.getPartDescription() << endl; cout << "Quantity: " << invoice.getQuantity() << endl; cout << "Price per item: $" << invoice.getPricePerItem() << endl; cout << "Invoice amount: $" << invoice.getInvoiceAmount() << endl; // modify the invoice data members invoice.setPartNumber( "123456" ); invoice.setPartDescription( "Saw" ); invoice.setQuantity( -5 ); // negative quantity, so quantity set to 0 invoice.setPricePerItem( 10 ); cout << "\nInvoice data members modified.\n\n"; // display the modified invoice data members and calculate new amount cout << "Part number: " << invoice.getPartNumber() << endl; cout << "Part description: " << invoice.getPartDescription() << endl; cout << "Quantity: " << invoice.getQuantity() << endl; cout << "Price per item: $" << invoice.getPricePerItem() << endl; cout << "Invoice amount: $" << invoice.getInvoiceAmount() << endl; } // end main
Anonymous
@Psalmbonga what's your problem? it looks you've completed it
Anonymous
It's not running
So fix it. It's probably not code related or tell us what the problem is, lol
Anonymous
It's not running
maybe because there's no Invoice class included in your project?!
Anonymous
you've posted main but that class.
Anonymous
/get cbook
rdrg109
This channel should have a bot that recognize basic homework questions so that it notifies the user that this is not allowed in this group. Whenever I visit this chat, I read that type of questions.
rdrg109
I know. The problem is that I'm currently busy with other projects, but I just wanted to pointed it out just in case someone is willing to invest time for solving this common problem.
klimi
👍 yup
adult breastfeeding
tbh
adult breastfeeding
learning c++ first is better
Abdulwahab
learning c++ first is better
I firstly Started by learning HTML and Qbasic
A
Does anyone have c++ notes cleanly written?
Prince Of Persia
Does anyone have c++ notes cleanly written?
Mine is in farsi language😅
A
Why?
I need to study 😑
Abhishek
I need to study 😑
Write a bunch of programs with the concepts you need to learn and be done with it...
Suka
Does anyone have c++ notes cleanly written?
like this https://rosettacode.org/wiki/Averages/Root_mean_square
klimi
learning c++ first is better
If you want to learn C, learning c++ first is better?
Prince Of Persia
C is complected (lower level) While C++ has classes so it has cleaner interface But most of C++ programmers need to know C programming too (some functions and stuff like jni and ...)
klimi
Depends on yourself
i don't undestand... if i want to learn C, why would i be learning c++ first? it doesn't make any sense
Thumar Viren Mahendrabhai
C language basic all programs
Prince Of Persia
i don't undestand... if i want to learn C, why would i be learning c++ first? it doesn't make any sense
So just learn C But C isn't so comfortable for projects (no classes and generics)
Thumar Viren Mahendrabhai
Program joy cha
Thumar Viren Mahendrabhai
C language program
Prince Of Persia
C language basic all programs
I don't think so
Prince Of Persia
Most of programs including games ,use C++ instead of C
klimi
most of web apps use javascript instead of C++, same point, they are different languages
Prince Of Persia
C language basic all programs
Yeah but you did say something else
Thumar Viren Mahendrabhai
C program example