File tree Expand file tree Collapse file tree 12 files changed +223
-0
lines changed Expand file tree Collapse file tree 12 files changed +223
-0
lines changed Original file line number Diff line number Diff line change 1+ {
2+ "configurations" : [
3+ {
4+ "name" : " Win32" ,
5+ "includePath" : [
6+ " ${workspaceFolder}/**"
7+ ],
8+ "defines" : [
9+ " _DEBUG" ,
10+ " UNICODE" ,
11+ " _UNICODE"
12+ ],
13+ "windowsSdkVersion" : " 10.0.17763.0" ,
14+ "compilerPath" : " C:\\ MinGW\\ bin\\ gcc.exe" ,
15+ "cStandard" : " c11" ,
16+ "cppStandard" : " c++17" ,
17+ "intelliSenseMode" : " msvc-x64" ,
18+ "browse" : {
19+ "path" : [
20+ " ${workspaceRoot}" ,
21+ " C:\\ MinGW\\ lib\\ gcc\\ mingw32\\ 8.2.0\\ include\\ c++"
22+ ],
23+ "limitSymbolsToIncludedHeaders" : true ,
24+ "databaseFilename" : " "
25+ }
26+ }
27+ ],
28+ "version" : 4
29+ }
Original file line number Diff line number Diff line change 1+ {
2+ // Use IntelliSense to learn about possible attributes.
3+ // Hover to view descriptions of existing attributes.
4+ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+ "version" : " 0.2.0" ,
6+ "configurations" : [
7+ {
8+ "name" : " (gdb) Launch" ,
9+ "type" : " cppdbg" ,
10+ "request" : " launch" ,
11+ "program" : " ${workspaceFolder}/a.exe" ,
12+ "args" : [],
13+ "stopAtEntry" : false ,
14+ "cwd" : " ${workspaceFolder}" ,
15+ "environment" : [],
16+ "externalConsole" : true ,
17+ "MIMode" : " gdb" ,
18+ "miDebuggerPath" : " C:\\ MinGW\\ bin\\ gdb.exe" ,
19+ "setupCommands" : [
20+ {
21+ "description" : " Enable pretty-printing for gdb" ,
22+ "text" : " -enable-pretty-printing" ,
23+ "ignoreFailures" : true
24+ }
25+ ],
26+ "preLaunchTask" : " build debug"
27+ }
28+ ]
29+ }
Original file line number Diff line number Diff line change 1+ {
2+ // See https://go.microsoft.com/fwlink/?LinkId=733558
3+ // for the documentation about the tasks.json format
4+ "version" : " 2.0.0" ,
5+ "tasks" : [
6+ {
7+ "label" : " echo" ,
8+ "type" : " shell" ,
9+ "command" : " C:\\ MinGW\\ bin\\ g++.exe" ,
10+ "args" : [
11+ " -g" ,
12+ " main.cpp"
13+ ],
14+ "group" : {
15+ "kind" : " build" ,
16+ "isDefault" : true
17+ }
18+ }
19+ ]
20+ }
Original file line number Diff line number Diff line change 1+ #include " Buffer.h"
2+
3+ // Constructors
4+ Buffer::Buffer (int length, int init){
5+ this ->values = new int [length];
6+ this ->length = length;
7+ this ->average = init;
8+ this ->init = init;
9+ this ->fill (init);
10+ }
11+
12+
13+ // Getters
14+ int Buffer::calcAverage (){
15+ float sum = 0 ;
16+
17+ for (int i = 0 ; i < this ->length ; i++)
18+ sum += this ->values [i];
19+
20+ this ->average = sum / this ->length ;
21+
22+ return this ->average ;
23+ }
24+
25+ int Buffer::getAverage (){
26+ return this ->average ;
27+ }
28+
29+ int Buffer::getAt (int position){
30+ return this ->values [position];
31+ }
32+
33+ bool Buffer::empty (){
34+ return this ->average == this ->init ;
35+ }
36+
37+ int Buffer::size (){
38+ return this ->length ;
39+ }
40+
41+
42+ // Setters
43+ void Buffer::fill (int value){
44+ for (int i = 0 ; i < this ->length ; i++)
45+ this ->values [i] = value;
46+
47+ this ->calcAverage ();
48+ }
49+
50+ void Buffer::insert (int value){
51+ if (!this ->empty ()){
52+ // Move array values
53+ for (int i = this ->length -1 ; i > 0 ; i--)
54+ this ->values [i] = this ->values [i - 1 ];
55+
56+ // Insert new value
57+ this ->values [0 ] = value;
58+
59+ // Update the average variable
60+ this ->calcAverage ();
61+ }
62+ // Insert the first value on array
63+ else {
64+ this ->fill (value);
65+ }
66+ }
Original file line number Diff line number Diff line change 1+ #ifndef BUFFER_H
2+ #define BUFFER_H
3+
4+ class Buffer {
5+ public:
6+ // Constructors
7+ Buffer (int , int );
8+
9+ // Getters
10+ int calcAverage ();
11+ int getAverage ();
12+ int getAt (int );
13+ bool empty ();
14+ int size ();
15+
16+ // Setters
17+ void fill (int );
18+ void insert (int );
19+
20+ private:
21+ int init;
22+ int *values;
23+ int length;
24+ int average;
25+ };
26+
27+
28+ #endif
You can’t perform that action at this time.
0 commit comments