This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const EventEmitter = require('node:events'); | |
| class Timer extends EventEmitter { | |
| constructor(){ | |
| super(); | |
| this.intervalId = null; | |
| } | |
| start(){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const EventEmitter = require('node:events'); | |
| class Counter extends EventEmitter { | |
| count = 0 | |
| increment(){ | |
| this.count++; | |
| } | |
| decrement(){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // create a curried function | |
| const introSelf = lastName => firstName => console.log(`My name is ${firstName} ${lastName}`) | |
| // use curried function | |
| introSelf("Youdiowei")("Eteimorde") | |
| // Output: My name is Eteimorde Youdiowei | |
| // partially apply the curried function to create a new one | |
| const introDoe = introSelf("Doe") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "Time.h" | |
| Time::Time(int hr, int min, int sec){ | |
| setTime(hr, min, sec); | |
| } | |
| void Time::setTime(int h, int m, int s){ | |
| hour = ( h >= 0 && h < 24 ) ? h : 0; | |
| minute = ( m >= 0 && m < 60 ) ? m : 0; | |
| second = ( s >= 0 && s < 60 ) ? s : 0; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| using namespace std; | |
| void fib(){ | |
| static int a = 0; | |
| static int b = 1; | |
| static int c; | |
| cout << a << endl; | |
| c = a; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Member-function definition for class time | |
| #include <iostream> | |
| using std::cout; | |
| #include <iomanip> | |
| using std::setfill; | |
| using std::setw; | |
| #include "Time.h" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Implementation for class SalesPerson | |
| #include <iostream> | |
| using std::cout; | |
| using std::cin; | |
| using std::endl; | |
| using std::fixed; | |
| #include <iomanip> | |
| using std::setprecision; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Implementation file for Count class | |
| #include <iostream> | |
| #include "Count.h" | |
| using std::cout; | |
| using std::endl; | |
| // set value of private data member x | |
| void Count::setX(int value){ | |
| x = value; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Member-function definitions for class Time | |
| #include <iostream> | |
| using std::cout; | |
| #include <iomanip> | |
| using std::setfill; | |
| using std::setw; | |
| #include "Time.h" // include definition of class Time from Time.h |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // GradeBook Implementation | |
| #include <iostream> | |
| using std::cout; | |
| using std::endl; | |
| #include "GradeBook.h" // include interface | |
| // constructor implementation | |
| GradeBook::GradeBook(string name){ |