Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added expense tracker app & DSA programs & various pointers in c++ #199

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions C++/Max_consecutive_ones_sliding_window.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include <bits/stdc++.h>
#include <iostream>
using namespace std;

typedef long long ll;
typedef long long unsigned llu;

int main()
{
int n, k;
cin >> n >> k;

vector<int> vec(n);
for (auto &i : vec)
cin >> i;

int zeroesCnt = 0, i = 0, ans = 0;
for (int j = 0; j < vec.size(); j++)
{
if (vec[j] == 0)
zeroesCnt++;

while (zeroesCnt > k)
{
if (vec[i] == 0)
zeroesCnt--;
i++;
}

// zerosCnt <=k
ans = max(ans, j - i + 1);
}

cout << ans << endl;
return 0;
}
41 changes: 41 additions & 0 deletions C++/Shared_pointer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include<iostream>
#include<memory>
using namespace std;

class foo
{
int x;

public:

foo(int x):x(x)
{}

int getx()
{return x;}

~foo()
{
cout<<"DESTRUCT"<<endl;
}

};

int main()
{
// foo *f=new foo(35); // the problem is that we forgot to destroy the DMA block, hence it leads to memory leak.
// cout<<f->getx()<<endl; // Using delete will be necessary in this but as we can't always remember to do so. SO WE USE UNIQUE POINTER.
// delete f;

// Another Method shared_ptr<foo> sp(new foo(35));
shared_ptr<foo> sp = make_shared<foo>(35); // The advantages of shared pointer is that it will destroy the memory block it is pointing to when the
cout<<sp->getx()<<endl; // last remaining shared_ptr (pointing to object) will get destroyed, and obviously when object is gonna destroyed, the destructor will be called.
shared_ptr<foo> sp1=sp;
shared_ptr<foo> sp2=sp; // &sp2=sp; AND *sp2=&sp; will not work.
cout<<sp.use_count()<<endl;
shared_ptr<foo> sp3=sp;
cout<<sp3.use_count()<<endl; //Destructor will run only once regardless of how many shared_ptrs are pointing to the object.
} // It is a smart pointer with reference-count copy semantics..
// Actually, in shared_ptr : we have two things 1)First is your object(memory block) you created called Managed object.
// 2) Second One is called Control block, which come in act when we assign the VALUE of one shared_ptr to other, it increases
// the reference count with the same.
59 changes: 59 additions & 0 deletions C++/Unique_pointer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#include<iostream>
#include<memory> // Header file having declaration of the unique pointer
using namespace std;

class foo
{
int x;


public:

explicit foo(int x):x(x)
{}

int getx()
{
return x;
}

~foo()
{
cout<<"Foo Dest"<<endl;
}
};

int main()
{
// foo *f=new foo(10); // the problem is that we forgot to destroy the DMA block, hence it leads to memory leak.
// cout<<f->getx()<<endl; // Using delete will be necessary in this but as we can't always remember to do so. SO WE USE UNIQUE POINTER.
// delete f;

unique_ptr<foo> p (new foo(40)); // NO EXCEPTION SAFETY
// unique_ptr<foo> p1 = make_unique<foo>(40); (should use make_unique(exception safe))

cout<<p->getx()<<endl; // The advantages of unique pointer is that it will destroy the memory block it is pointing to when it

return 0; // itself will be destroyed, and obviously when object is gonna destroyed, the destructor will be called.
// We can't copy that address to any pointer to which unique pointer is pointing. Only unique pointer
// has ownership for that DMA block, but we can make a pointer to pointer to that to access that memory block.

// IMP ----- We can move the ownership of the unique_ptr to another one(unique_ptr) by using move()
/* unique_ptr<foo> p1 = move(p); Here the ownership has been moved from "p" to "p1", now p points to that object(having the ownership) and p points null now.

// IMP ------ We can release the ownership of the unique_ptr and can make it point by a normal (class)pointer by using release().
foo *p2 = p1.release()

// IMP ------ We can swap the managed objects of the unique_ptr(s) by using swap() function.
unique_ptr<foo> p3 = swap(p1);

// IMP ------ We can reset the unique_ptr by using reset() function.
p4.reset(p2) HERE 'p2' SHOULD BE A NORMAL (CLASS) POINTER. (Considering that 'p4' is pointing to a managed object(having ownership))
Hence, Now the p4 will point to what p2 is pointing, and that previous managed object which was pointed by p4 will get deleted.

*/

}



Empty file added C++/Weak_pointer.cpp
Empty file.
58 changes: 58 additions & 0 deletions C++/dp_Combinations_to_make_a_sum.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#include <bits/stdc++.h>
#include <iostream>
using namespace std;

#define fo(u, k, n) for (u = k; u <= n; u++)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define allr(c) c.rbegin(), c.rend()
#define mem(x) memset(x, 0, sizeof(x))
#define PI 3.1415926535897932384626

typedef long long ll;
typedef long long unsigned llu;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<vll> vvll;
typedef map<ll, ll> ml;
typedef map<ll, bool> mlb;

const int MOD = 1000000007;

class Solution
{
public:
long combinationSum4(vector<long> &nums, int target)
{

long long unsigned dp[target + 1];
dp[0] = 1;

for (long i = 1; i <= target; i++)
{

dp[i] = 0;
for (long j = 0; j < nums.size(); j++)
{

if (i - nums[j] >= 0)
{
dp[i] = dp[i] + dp[i - nums[j]];
}
}
}

return dp[target];
}
};

int main()
{
Solution obj1;
vector<long> nums{1, 2, 3};
cout << obj1.combinationSum4(nums, 4) << endl;

return 0;
}
54 changes: 54 additions & 0 deletions HTML/expense-tracker/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<link rel="stylesheet" href="style.css" />
<title>Expense Tracker</title>
</head>
<body>
<h2 class="name">Expense Tracker</h2>

<div class="container">
<h4>Your Balance</h4>
<h1 id="balance">$0.00</h1>

<div class="inc-exp-container">
<div>
<h4>Income</h4>
<p id="money-plus" class="money plus">+$0.00</p>
</div>
<div>
<h4>Expense</h4>
<p id="money-minus" class="money minus">-$0.00</p>
</div>
</div>

<h3>History</h3>
<ul id="list" class="list">
<!-- <li class="minus">
Cash <span>-$400</span><button class="delete-btn">x</button>
</li> -->
</ul>

<h3>Add new transaction</h3>
<form id="form">
<div class="form-control">
<label for="text">Remarks</label>
<input type="text" id="text" placeholder="Remarks..." />
</div>
<div class="form-control">
<label for="amount"
>Amount <br />
(negative - expense, positive - income)</label
>
<input type="number" id="amount" placeholder="Enter amount..." />
</div>
<button class="btn">Add transaction</button>
</form>
</div>

<script src="script.js"></script>
</body>
</html>
26 changes: 26 additions & 0 deletions HTML/expense-tracker/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Expense Tracker

A browser based expense tracker to keep track of income and expenses. Add and remove items and save to local storage .

<hr>

![Screenshot (730)](https://user-images.githubusercontent.com/54171759/137636583-1403ccb8-98ec-4e1e-8e23-954f6b9ee078.png)

![Screenshot (729)](https://user-images.githubusercontent.com/54171759/137636650-7f6c06d8-f0c5-4cdf-a2e5-0d48d0577357.png)

<hr>

## Technologies Used

``` JavaScript, Html, CSS ```

<hr>

## Project Specifications

- Created UI for project
- Transaction items are displayed in DOM.
- Showing balance, expense and income totals
- Added new transation and reflecting in total
- Created delete button to delete items from DOM
- Persist to local storage
Loading