Page 1 of 1

Help in c++. Please read my code and fix the errors The Coin class represents any kind of coin, with a value. Examine th

Posted: Fri May 20, 2022 1:40 pm
by answerhappygod
Help in c++. Please read my code and fix the errors The Coin
class represents any kind of coin, with a value. Examine the Demo
program and modify the class definition adding the necessary data
member and the prototype for the coins() class function, which
returns the number of coins that exist at any time in your
program.
Help In C Please Read My Code And Fix The Errors The Coin Class Represents Any Kind Of Coin With A Value Examine Th 1
Help In C Please Read My Code And Fix The Errors The Coin Class Represents Any Kind Of Coin With A Value Examine Th 1 (46.58 KiB) Viewed 23 times
The Coin class represents any kind of coin, with a value. Examine the Demo program and modify the class definition adding the necessary data member and the prototype for the coins () class function, which returns the number of coins that exist at any time in your program. coin.h i #ifndef COINH 2 #define COIN H H 3 4 class Coin 5 ( 6 public: 7 Coin(double value); 8 -Coin(); 9 double value() const; 10 11 /* 12 * A static function, which returns 13 * the count of coins in scope 14 15 static unsigned int Coins(); 16 17 18 private: 19 double m value; 20 21 / 22 * A singular variable for this class, 23 * that keeps a count of the number of 24 * coins currently in scope. 25 */ 26 static unsigned int count; 27 28 #endif

Demo.cpp 1 #include <iostream> 2 #include <vector 3 3 using namespace std; 4 5 #include "coin.h" 6 7 int main() 8 8 { 9 { 10 Coin a[] = { {.1}, {.25}, {.25} }; 11 cout << "#1 coins: " << Coin::coins() << endl; 12 1 13 cout << "#2 coins: " « Coin::coins() << endl; 14 1 15 Coin a[] = { {.1}, {.25}, {.25}, {.65}, {.56}, {.01} }; 16 cout << "#3 coins: " « Coin::coins) << endl; 17 1 18 cout << "#4 coins: "« Coin::coins() << endl; 19] CodeCheck Reset Testing Demo.cpp Error: Demo.cpp: In function 'int main()': Demo.cpp:11:37: error: 'coins' is not a member of 'Coin' 111 cout << "#1 coins: " « Coin:: coins() << endl; Demo.cpp:13:34: error: 'coins' is not a member of 'Coin' 13 cout << "#2 coins: " « Coin::coins() << endl; Demo.cpp:16:37: error: 'coins' is not a member of 'Coin' 16 cout << "#3 coins: " « Coin:: coins() << endl; Demo.cpp:18:34: error: 'coins' is not a member of 'Coin' 18 cout << "#4 coins: " « Coin::coins() << endl; coin.cpp: In constructor 'Coin::Coin(double)': coin.cpp:9:4: error: 'num coins' was not declared in this scope 91 num coins++;

Error: Demo.cpp: In function 'int main()': Demo.cpp:11:37: error: 'coins' is not a member of 'Coin' 11 cout << "#1 coins: « Coin:: coins() << endl; 11 Demo.cpp:13:34: error: 'coins' is not a member of 'Coin' 13 cout << "#2 coins: " « Coin::coins() < endl; Demo.cpp:16:37: error: 'coins' is not a member of 'Coin' cout << "#3 coins: " « Coin:: coins() << endl; 16 Demo.cpp:18:34: error: 'coins' is not a member of 'Coin' 18 cout << "#4 coins: << Coin::coins() << endl; coin.cpp: In constructor 'Coin::Coin(double)': coin.cpp:9:4: error: 'num_coins' was not declared in this scope 9 num_coins++; coin.cpp: In destructor 'Coin::-Coin()': coin.cpp:14:4: error: 'num_coins' was not declared in this scope 14 num coins--; coin.cpp: At global scope: coin.cpp:19:5: error: 'int Coin:: num_coins' is not a static data member of 'class Coin' 19 int Coin:: num_coins = 0; 1 coin.cpp:20:5: error: no declaration matches 'int Coin:: coins()' 20 int Coin::coins() { return num_coins; } coin.cpp:20:5: note: no functions named 'int Coin::coins()' In file included from coin.cpp:3: coin.h:4:7: note: 'class Coin' defined here 4 class Coin Ae Score 0