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

All Submissions #6

Open
wants to merge 11 commits 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
Binary file added ronak/assignment-1/Theory_Questions.doc
Binary file not shown.
666 changes: 666 additions & 0 deletions ronak/assignment-1/hw-1.cpp

Large diffs are not rendered by default.

123 changes: 123 additions & 0 deletions ronak/assignment-2/hw-2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

void estimatePi(int maxTerms){
float display_array[maxTerms];
float pi = 0.0f;
for(int j = 0; j < maxTerms; j++){
pi += pow(-1.00,j)*(4.00/(2.00*j+1));
display_array[j] = pi;
}

for(int k = 0; k < maxTerms; k++){
cout << "(Up to) Number of Terms in the Series = " << k+1 << ", Value of Pi = " << fixed << setprecision(5) << display_array[k] << endl;
}
}

void findPythagorasTriples(int max){
for(int i = 1; i <= max; i++){
for(int j = 1; j <= max; j++){
for(int k = 1; k<= max; k++){
if(pow(i,2) + pow(j,2) == pow(k,2)){
cout << "Triple Found (" << i << "," << j << "," << k << ")" << endl;
}
}
}
}
}

void deMorgan(int x, int y, int expr_serial_num){

bool expr = !(x < 5) && !(y >= 7);
bool eq_expr = !((x < 5) || (y >= 7));

int g = 7;
bool expr2 = !(x == y) || !(g != 5);
bool eq_expr2 = !((x == y) && (g != 5));

int h = 5;

bool expr_next = !(x == y) || !(h != 5);
bool eq_expr_next = !((x == y) && (h != 5));

bool expr3 = !((x <= 8) && (y > 4));
bool eq_expr3 = !(x <= 8) || !(y > 4);

bool expr4 = !((x > 4) || (y <= 6));
bool eq_expr4 = !(x > 4) && !(y <= 6);

switch(expr_serial_num){

case 1:


if(expr == eq_expr){
cout << "De Morgan's Law Holds!";
} else{
cout << "De Morgan's Law Doesn't Hold!";
}

break;

case 2:

if((expr2 == eq_expr2) && (expr_next == eq_expr_next)){
cout << "De Morgan's Law Holds!";
} else{
cout << "De Morgan's Law Doesn't Hold!";
}

break;

case 3:

if(expr3 == eq_expr3){
cout << "De Morgan's Law Holds!";
} else{
cout << "De Morgan's Law Doesn't Hold!";
}

default:

if(expr4 == eq_expr4){
cout << "De Morgan's Law Holds!";
} else{
cout << "De Morgan's Law Doesn't Hold!";
}

}
}

void removeBreak(){

int count;
for ( count = 1; (count <= 10) && (count != 5); ++count )
{
cout << count << " " << endl;
}
cout << "\n Broke out of loop at count = " << count << endl;
}

int main() {

/* Estimate Pi */
estimatePi(1000);

/* Pythagoras */
findPythagorasTriples(500);

/* DeMorgan */
/* The third argument is to indicate which expression we are checking for */
deMorgan(3,3,4); //This should always return that "DeMorgan's Laws hold.

/*Break and Continue */
removeBreak();

return 0;
}



53 changes: 53 additions & 0 deletions ronak/assignment-3/TowerHanoi.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//
// Created by Ronak Tali on 9/28/22.
//

#ifndef FIRST_PROJ_TOWERHANOI_H
#define FIRST_PROJ_TOWERHANOI_H

#endif //FIRST_PROJ_TOWERHANOI_H

/* Reference from https://iq.opengenus.org/tower-of-hanoi/ */

#include<stack>

using namespace std;

class toh{ //To make a variable which can keep a track of source, auxiliary and destination pole.
public:
char from;
char to;
char aux;
int n;
};

void towerOfHanoi(int n, char source, char auxiliary, char destination){

stack<toh> st; //Declaring a stack.

while(n>=1 or !st.empty()){
while(n>=1){ //Save the current state and move to the towerOfHanoi(n-1,source,destination,auxiliary).

toh cur;
cur.from=source;
cur.aux=auxiliary;
cur.to=destination;
cur.n=n;
st.push(cur);
swap(destination,auxiliary);
n--;
}

toh cur = st.top();
st.pop();
cout << "Move disk " << cur.n << " from rod " << cur.from << " to rod " << cur.to << endl;

if(cur.n>=1){
source=cur.aux; // Simulates the towerOfHanoi(n-1,auxiliary,source,destination) of Recursive Step.

auxiliary=cur.from;
destination=cur.to;
n=cur.n-1;
}
}
}
Loading