0

Sololearn C++ 78.2 Your queue! Help!

Here is my code can you find out what is wrong pls? #include <iostream> using namespace std; template <class T> class Div { public: Div (T x, T y) { cout <<x / y<<endl; } }; //your code goes here int main () { string a, b; cin >> a >> b; int x, y; cin >> x >> y; Div <string> d2(a, b); Div <int> d1(x, y); }

17th Nov 2021, 3:24 PM
Boong Bing
4 Antworten
+ 2
Morteza Hajji string header is included in iostream header already.
17th Nov 2021, 4:40 PM
Mehran
Mehran - avatar
+ 1
There for the first input type "string" , its invalid operation x/y .. how string decided by a string ?
17th Nov 2021, 3:50 PM
Jayakrishna 🇮🇳
+ 1
Beside what Jayakrishna🇮🇳 said, you should include string library, (#include <string>).
17th Nov 2021, 4:23 PM
Morteza Hajji
0
Ps. Sorry I copied wrong code I tried to skip it and rethink it again here’s the real code: #include <iostream> using namespace std; //change the class to a template template <class T> class Queue { private: int *arr; int count; public: Queue(int size) { arr = new int[size]; count = 0; } //my code template <class T>: void add(int elem) { arr[count] = elem; count++; } void get(int index) { cout << arr[index]<<endl; } }; int main() { Queue<string> q(4); q.add("James"); q.add("Andy"); q.add("Amy"); q.get(2); Queue <int> n(2); n.add(42); n.add(33); n.get(1); return 0; }
22nd Nov 2021, 2:43 PM
Boong Bing