Skip to content

Instantly share code, notes, and snippets.

View tamirazrab's full-sized avatar

Tamir Azrab tamirazrab

  • JazzCash
  • Pakistan
  • 13:29 (UTC +05:00)
View GitHub Profile
@tamirazrab
tamirazrab / vp-question1.cs
Last active June 28, 2020 12:50
Visual programming
public class Worker {
public int cnic {
get;
set;
}
public string name {
get;
set;
}
public string address {
public class saving_account {
public double calculateFutureValue( double presentValue, double interestRate, int monthsPeriod ) {
return ( presentValue * Math.Pow( ( interestRate + 1 ) , monthsPeriod ) );
}
}
public class Driver {
public static void Main( string[] args ) {
double presentValue = 0.0;
double interestRate = 0.0;
public class Exponents {
public int power( int base, int exponent ) {
if ( base <= 0 || exponent < 0 )
return 1;
int result = 0;
for( int i = 1; i <= exponent; ++i )
result = result * base;
return result;
@tamirazrab
tamirazrab / knapSack.cpp
Last active July 2, 2020 14:45
Simple KnapSack problem, puts weights with maximum profit into bag until it reaches it's maximum capacity, doesn't work well if good profits with less weights are put after. Good with first come first serve basis.
#include <iostream>
using namespace std;
int max ( int first , int second ) {
return first > second ? first : second;
}
int knapSack ( int weight [] , int value [ ] , int totalCap, int totalItems ) {
if( totalItems == 0 || totalCap == 0 )
return 0;
@tamirazrab
tamirazrab / casino.cpp
Created July 1, 2020 16:12
Cool little project of casino offers 3 different games, made it for programming fundamentals course as final project.
/*
Made by: Tamir Azrab
It may sound easy to just remove this comment
or maybe replace my name with yours but it ain't
easy to write this long code and the time being invested
so please do give credits if you can.
- Ignore above and copy as much as you want.
*/
@tamirazrab
tamirazrab / rotateImage.cpp
Last active July 2, 2020 14:21
Rotation of image represented in 2d array, shifting rows into column ( transpose ) then swapping horizontally.
#include <iostream>
using namespace std;
void swap( int* first, int* second ) {
int temp = *first;
*first = *second;
*second = temp;
}
void rotateImage( int array [ ] [ 3 ] , int size ) {
@tamirazrab
tamirazrab / oop-project.md
Last active July 6, 2020 06:59
Project description which was given for last semester as end project for subject.

Object Oriented Programming

Final Project

Implement Banking system using OOP concepts like encapsulation, access specification, late binding, polymorphism and exception handling using C++.

The scenario has been explained below:

There exist accounts of various types like Current, Savings and Student. Every amount would have information like account number (integer), account title (string), current balance, birth date of account holder, etc. Every account instance would provide getter and setter methods for these attributes. Additionally, every account instance would provide methods for deposit and withdrawal of amount.

For every withdrawal of amount from current account, 5% of withdrawal amount would be deducted (an additional transaction) from the remaining account and no extra amount would be added to on each deposit. Similarly, for each deposit in a savings account, 7% of the deposited amount will be added (an additional transaction) to the account’s balance and no amount would be deducted from the

@tamirazrab
tamirazrab / poorPalindrome.cpp
Created July 6, 2020 07:00
Stupid solution takes more space plus time for execution.
bool checkPalindrome(std::string inputString) {
if ( inputString.length() < 2 )
return true;
string input_copy;
int j = 0;
for ( int i = inputString.length() - 1; i >= 0; --i, ++j )
input_copy [ j ] = inputString [ i ];
for ( int i = 0; i < inputString.length(); ++i )
@tamirazrab
tamirazrab / bestPalindrome.cpp
Created July 6, 2020 07:39
A sexiest solution which beautifully targets mid points of strings just in one comparison it would do the trick.
#include <iostream>
using namespace std;
bool checkPalindrome ( string item ) {
int n = item.length() / 2;
if ( n < 2 ) // if string contains only one element
return true;
int i = item [ n ]; // pointing towards mid position - can be omitted didn't really used though anywhere.
@tamirazrab
tamirazrab / sudoku2-bad-solution.cpp
Last active July 8, 2020 07:59
Stupid illogical solution might need it for later.
bool sudoku2(std::vector<std::vector<char>> grid) {
int n = grid.size();
int traceNumber [ 9 ] { 0 };
int trackBack [ 9 ] [ 9 ] { 0 };
int currentElement = 0;
for ( int i = 0; i < n; ++i ) {
for ( int j = 0; j < n; ++j ) {
currentElement = grid [ i ] [ j ] - '0';
if ( currentElement < 1 )
continue;