olli
Curve.h: class Curve { ... CurveType m_type = CurveType::GRAPH; std::vector<Point> m_points = {}; ... Curve.cpp: ... m_type = curveType; m_points = points; ... why am i getting a "variable Curve::m_type" is uninitialized warning (visual studio)?
can you share more code? MSVC shows no warnings for this #include <vector> #include <utility> using Point = std::pair<double, double>; enum class CurveType { GRAPH }; class Curve { std::vector<Point> m_points = {}; CurveType m_type = CurveType::GRAPH; public: Curve(CurveType curveType, const std::vector<Point>& Points) { m_type = curveType; m_points = Points; } }; int main() { Curve C { CurveType::GRAPH, {} }; return 0; } https://godbolt.org/z/zaxbWfjPx
Dima
/ban @bunqeu go fuck yourself 🥰
Anonymous
Sorry, does anyone think using Android CPP compiler can be reliable. I'm learning CPP(ebook: beginner's guide in understanding the principles of programing in C++ by Byarne Stroustrup) without a laptop, so I use my phone, but now I'm stuck on the "vector" program.
Anonymous
whats the history of programming?
ꠋꠋꠋ ☬ ]ᯱꠋꠋꠋꠋꠋꠋꠋꠋꠋꠋꠋꠋꠋꠋ ⨳ࣩࣩࣩࣩࣩࣩࣩࣩࣩࣩࣩࣩࣩࣩࣩࣩࣩࣩࣩࣩࣩࣩࣩࣩࣩࣩࣩࣩࣩࣩࣩࣩࣩࣩࣩࣩࣩࣩࣩࣩ
Vitrag
in beginning... i use android cpp compiler app... it's like computer...
Even I'm using my android too but compiler are such a pain sometimes
Raaaviiii
#include<stdio.h> #include<math.h> int distance(int x1,int y1,int x2,int y2); int point_inside_triangle(); int area_of_triangle(int x1,int y1,int x2,int y2,int x3,int y3); int main() { int x1,y1,x2,y2,x3,y3,x,y,area; printf("enter the x and y co ordinates of vertex 1: \n"); scanf("%d%d",&x1,&y1); printf("enter the x and y co ordinates of vertex 2: \n"); scanf("%d%d",&x2,&y2); printf("enter the x and y co ordinates of vertex 3: \n"); scanf("%d%d",&x3,&y3); area_of_triangle(x1,y1,x2,y2,x3,y3); printf("area of triangle is:%d\n",area); printf("enter the points x,y to check whether they lies inside triangle or not:\n"); scanf("%d%d",&x,&y); point_inside_triangle(x,y); if(area_of_triangle(x1,y1,x2,y2,x3,y3)==1) printf("point lies inside triangle\n"); else printf("point lies outside triangle\n"); return 0; } int distance(int x1,int y1,int x2,int y2) { int dist; dist=sqrt(pow((x2-x1),2)+pow((y2-y1),2)); return (dist); } int area_of_triangle(int x1,int y1,int x2,int y2,int x3,int y3) { int S1,S2,S3,S,area; S1=distance(x1,y1,x2,y2); S2=distance(x1,y1,x3,y3); S3=distance(x2,y2,x3,y3); S=(S1+S2+S3)/2; area=sqrt(S*(S-S1)*(S-S2)*(S-S3)); return (area); } int point_inside_triangle(int x,int y,int x1, int y1, int x2, int y2, int x3, int y3,int area) { int A1,A2,A3,A; A1=area_of_triangle(x1,y1,x2,y2,x,y); A2=area_of_triangle(x1,y1,x3,y3,x,y); A3=area_of_triangle(x3,y3,x2,y2,x,y ); A=A1+A2+A3; if(A==area) return 1; else return 0; } can anyone tell me what is the mistake in this code please??
Rakesh
#include<stdio.h> #include<math.h> int distance(int x1,int y1,int x2,int y2); int point_inside_triangle(); int area_of_triangle(int x1,int y1,int x2,int y2,int x3,int y3); int main() { int x1,y1,x2,y2,x3,y3,x,y,area; printf("enter the x and y co ordinates of vertex 1: \n"); scanf("%d%d",&x1,&y1); printf("enter the x and y co ordinates of vertex 2: \n"); scanf("%d%d",&x2,&y2); printf("enter the x and y co ordinates of vertex 3: \n"); scanf("%d%d",&x3,&y3); area_of_triangle(x1,y1,x2,y2,x3,y3); printf("area of triangle is:%d\n",area); printf("enter the points x,y to check whether they lies inside triangle or not:\n"); scanf("%d%d",&x,&y); point_inside_triangle(x,y); if(area_of_triangle(x1,y1,x2,y2,x3,y3)==1) printf("point lies inside triangle\n"); else printf("point lies outside triangle\n"); return 0; } int distance(int x1,int y1,int x2,int y2) { int dist; dist=sqrt(pow((x2-x1),2)+pow((y2-y1),2)); return (dist); } int area_of_triangle(int x1,int y1,int x2,int y2,int x3,int y3) { int S1,S2,S3,S,area; S1=distance(x1,y1,x2,y2); S2=distance(x1,y1,x3,y3); S3=distance(x2,y2,x3,y3); S=(S1+S2+S3)/2; area=sqrt(S*(S-S1)*(S-S2)*(S-S3)); return (area); } int point_inside_triangle(int x,int y,int x1, int y1, int x2, int y2, int x3, int y3,int area) { int A1,A2,A3,A; A1=area_of_triangle(x1,y1,x2,y2,x,y); A2=area_of_triangle(x1,y1,x3,y3,x,y); A3=area_of_triangle(x3,y3,x2,y2,x,y ); A=A1+A2+A3; if(A==area) return 1; else return 0; } can anyone tell me what is the mistake in this code please??
Passing values to point_inside_triangle function In line 20
Anonymous
Hey everyone. I was wondering if the linker command failed with exit code 1, undefined symbols has sth to do with having a class template. Can't I have template class and choose a particular data type from another class in a separate header file? Please help me out.
Anonymous
Hey everyone. I was wondering if the linker command failed with exit code 1, undefined symbols has sth to do with having a class template. Can't I have template class and choose a particular data type from another class in a separate header file? Please help me out.
Can you show us what exactly you are trying to do through an MCVE? As long as the template class is fully visible at the point of instantiation and the template argument alsosatisfies the requirements of the template parameter it should not be an issue
Anonymous
https://stackoverflow.com/help/minimal-reproducible-example
Anonymous
Can you show us what exactly you are trying to do through an MCVE? As long as the template class is fully visible at the point of instantiation and the template argument alsosatisfies the requirements of the template parameter it should not be an issue
I have a linked list class in a header file called linklist.h which is a template for having admins, members data types that are in separate header files. When I try to load data from a file to admin type of linkedlist, it says no matching constructor for initialization of Admin.
Anonymous
I have a linked list class in a header file called linklist.h which is a template for having admins, members data types that are in separate header files. When I try to load data from a file to admin type of linkedlist, it says no matching constructor for initialization of Admin.
It is not possible to help you this way. We don't have magic crystal balls to predict what your code would be from just a few sentences in English. Good luck trying to get help from somwhere else
Abhinav
#include<stdio.h> #include <string.h> struct student{ int rollno; char name[10]; }; int main(){ int i; struct student st[5]; printf("Enter Records of 5 students"); for(i=0;i<5;i++){ printf("\nEnter Rollno:"); scanf("%d",&st[i].rollno); printf("\nEnter Name:"); scanf("%s",&st[i].name); } printf("\nStudent Information List:"); for(i=0;i<5;i++){ printf("\nRollno:%d, Name:%s",st[i].rollno,st[i].name); } return 0; }
artemetra 🇺🇦
can you share more code? MSVC shows no warnings for this #include <vector> #include <utility> using Point = std::pair<double, double>; enum class CurveType { GRAPH }; class Curve { std::vector<Point> m_points = {}; CurveType m_type = CurveType::GRAPH; public: Curve(CurveType curveType, const std::vector<Point>& Points) { m_type = curveType; m_points = Points; } }; int main() { Curve C { CurveType::GRAPH, {} }; return 0; } https://godbolt.org/z/zaxbWfjPx
sure, here's more code Curve.h: enum class CurveType { ENVELOPE = 0x01, LFO = 0x02, GRAPH = 0x03, }; class Curve { private: CurveType m_type = CurveType::GRAPH; std::vector<Point> m_points = {}; public: Curve(CurveType curveType, std::vector<Point> points); }; Curve.cpp: (msvc highlights here) Curve::Curve(CurveType curveType, std::vector<Point> points) { ... if (isValid) { // Do the actual construction m_type = curveType; m_points = points; }
Anonymous
What is offtopic group of the supergroup
Naina
In c++ strings program to print the longest word , how do I correct the runtime error saying terminator called after throwing an instance of ' std:: out_of_range' ?? The program gets terminated whithout showing the expected output even though code is correct
Anonymous
hi! the compiler implicitly defines 6 operations(default ctor, copy/move ctor, copy/move assignment, dtor). how can i know when it defines these operations or not? for example, if i define my copy ctor, the compiler still define the rest of these operations?
Anonymous
Mustapha
Who ever wrote this program, there is an error in it
Mustapha
stdin>:20:5: error: no matching function for call to 'point_inside_triangle' point_inside_triangle(x,y); ^~~~~~~~~~~~~~~~~~~~~ <stdin>:5:5: note: candidate function not viable: requires 0 arguments, but 2 were provided int point_inside_triangle(); ^ <stdin>:65:1: error: unknown type name 'can' can anyone tell me what is the mistake in this code please?? ^ <stdin>:65:11: error: expected ';' after top level declarator can anyone tell me what is the mistake in this code please?? ^ ; 3 errors generated. Here are the errors
klimi
and... where is the code?
klimi
like... it says where the error is... so your question is... redundand
Anonymous
Sorry guys! Someone to help me with this one,,,,, #include<iostream> #include<fstream> #include<cstring> using namespace std; int loggedin() { string password,username,pass,us; cout<<"enter password :\n"; cin>>password; cout<<"enter username :\n"; cin>>username; ifstream read; read.open("database.txt"); if(read.fail()); getline(read,us); getline(read,pass); read.close(); if(us==username && pass==password) { return 1; } else { return 0; } } int main () { int choice; cout<<"1 register :\n"; cout<<"2 loggin :\n"; cout<<"3 exit :\n"; cout<<"enter your choice :\n"; cin>>choice; if(choice==1) { string us,pass; cout<<"enter username :\n"; cin>>us; cout<<"enter password :\n"; cin>>pass; ofstream file; file.open("database.txt"); file<<us; cout<<endl; file<<pass; file.close(); main(); } else if(choice==2) { bool m= loggedin(); if(m!=1) { cout<<"wrong input\n"; main(); return 0; } else { cout<<"loggin successfully\n"; main(); return 1; } } } Even when the username and password are correct the program keeps saying "wrong input"
Anshul
If I am inserting n no. Of elements in a priority_queue (STL) then what will be the complexity of this.
Anshul
Pushing 1 element happens in O(logN) time but as numbers are added into the heap the N(no of elements in heap) will also increase. So it can't be O(nlogn)
Anshul
@K11M1 @gameraccoon @SilhouetteInDark @ollirz @chandradeepdey or anyone else. Please answer
klimi
@K11M1 @gameraccoon @SilhouetteInDark @ollirz @chandradeepdey or anyone else. Please answer
insert into priority queue can be even constant... depends on the implementation, and i don't know the STL implementation
klimi
that being sad... i think amortized time is used... not the worst case
Anshul
insert into priority queue can be even constant... depends on the implementation, and i don't know the STL implementation
In average case it's log n time. Can you or anyone tell me about what's going to be the average case complexity
Anonymous
Not sure what you mean where, they used writing modern C++ code. I mean not every app uses all of these (e.g. smart pointers in embedded software or with other places where "orthodox C++" used), but they are kind of essential parts of modern C++ and it usually helpful to know what they are at least and why they are exist.
depends on when you learnt. if before 2015, then there is a high chance that you would pick those up later. but if you learn with modern* books such as C++ Primer by Lippman or Stroustrup's book, you will learn them the first time. *modern is now a stretch for even those books though. lippman's book covers C++11, and Stroustrup's one covers C++14. hopefully newer editions of the books are coming soon.
Anonymous
for C++14, 17, 20 the new basic terms would be lambda, constexpr, and ranges for any C++ programmer and concepts for template metaprogrammers. not all of those are new, but some have been significantly expanded.
Anshul
Pavel or chandra deep anyone?
Anonymous
If I am inserting n no. Of elements in a priority_queue (STL) then what will be the complexity of this.
https://en.cppreference.com/w/cpp/container/priority_queue/push#Complexity
Anonymous
Can you people tell about this as well
also look at the "Effectively calls" part
Anonymous
the container used by priority_queue is std::vector<> by default, but you can change it by providing template arguments
Anonymous
the function is just inserting at the end of the std::vector and then shuffling the elements (heapifying)
Anonymous
Why bro
? that's how the standard defines it
Anonymous
Max
:/
:=
Anshul
https://en.cppreference.com/w/cpp/container/priority_queue/push#Complexity
I know this. I'm using vector as the container and the elements inserted are integers. Actually I want to know if I insert n integers then will it be O(n)
Anonymous
assuming the vector is never resized, the insertion is O(1)
Anonymous
O(1) + O(logn) for the heapify = O(logn)
Anonymous
repeat that n times
Anonymous
O(nlogn)
Anshul
Because think we want to get the top 3 largest elements of n integers. Then one way is I sort all the n numbers in o(nlogn). And then extract 3 top elements. Other way is using heap for it. Then if heap is also doing it in O(nlogn) what's the use
Anshul
Thus instead of inserting the element directly into the heap, we should first insert in some vector and then build a heap from the vector, which can be done in order of N time ?
Anonymous
also btw the exact problem you said is used as a disproof in an exercise in the CLRS book
Anonymous
if heaps insertion worked in O(n) time, then you would just pick the max element one by one and create a new sorted array in O(n) time
GodXAnubis
Hacktober fest anyone participating????
Anshul
also btw the exact problem you said is used as a disproof in an exercise in the CLRS book
Well I don't know about that but I see this in a video lecture and he was telling like ok if you have such a problem then it's better to use a heap instead of sorting the complete array.
Anonymous
if heaps insertion worked in O(n) time, then you would just pick the max element one by one and create a new sorted array in O(n) time
but there is a theorem that states that no comparison based sorting can take less than O(nlogn)
Anonymous
so heap sort must take at least O(nlogn)