Skip to content

Commit 68a7e09

Browse files
committed
Initial Code Upload
Initial upload of all code to GitHub
1 parent 490cbc1 commit 68a7e09

File tree

98 files changed

+8780
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+8780
-0
lines changed

C Sharp/Alt Char.cs

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
3+
https://www.hackerrank.com/challenges/alternating-characters
4+
5+
Problem Statement
6+
7+
Shashank likes strings in which consecutive characters are different. For example, he likes ABABA, while he doesn't like ABAA. Given a string containing characters A and B only, he wants to change it into a string he likes. To do this, he is allowed to delete the characters in the string.
8+
9+
Your task is to find the minimum number of required deletions.
10+
11+
Input Format
12+
13+
The first line contains an integer T, i.e. the number of test cases.
14+
The next T lines contain a string each.
15+
16+
Output Format
17+
18+
For each test case, print the minimum number of deletions required.
19+
20+
Constraints
21+
22+
1≤T≤10
23+
1≤ length of string ≤105
24+
Sample Input
25+
26+
5
27+
AAAA
28+
BBBBB
29+
ABABABAB
30+
BABABA
31+
AAABBB
32+
33+
Sample Output
34+
35+
3
36+
4
37+
0
38+
0
39+
4
40+
41+
Explanation
42+
43+
AAAA ⟹ A, 3 deletions
44+
BBBBB ⟹ B, 4 deletions
45+
ABABABAB ⟹ ABABABAB, 0 deletions
46+
BABABA ⟹ BABABA, 0 deletions
47+
AAABBB ⟹ AB, 4 deletions
48+
49+
*/
50+
51+
// I left the default hackerrank using statements. Had this been development code, I would have restricted using statements to minimize chances of namespace collisions.
52+
53+
using System;
54+
using System.Collections.Generic;
55+
using System.IO;
56+
class Solution {
57+
static void Main(String[] args) {
58+
int sent = Convert.ToInt32(Console.ReadLine());
59+
for( ; sent > 0; sent-=1){
60+
String target = Console.ReadLine();
61+
int count = 0;
62+
int length = target.Length - 1;
63+
for(int i = 0; i<length; ++i){
64+
if(target[i] == target[i + 1])
65+
++count;
66+
}
67+
Console.WriteLine(count);
68+
}
69+
}
70+
}

C++/Basic file IO.cpp

+182
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
/*
2+
3+
Incomplete class assignment that I assisted another student with file I/O
4+
5+
/************************************************************************************************************
6+
The file semgrades4.txt contains data for an unknown number of students in this format:
7+
Line 1: student name
8+
Line 2: six int quiz grades separated by a blank space
9+
Line 3: at least one (but possibly up to six) int project grades, separated by a blank space
10+
and terminated by -1
11+
Line 4: two int exam grades
12+
Line 5: int number of absences
13+
14+
Example of file entries:
15+
16+
Michael Palin
17+
70 30 70 80 85 90
18+
100 -1
19+
75 85
20+
4
21+
Eric Idle
22+
75 80 70 75 80 70
23+
70 80 90 100 -1
24+
70 88
25+
0
26+
*/
27+
28+
#include <iostream>
29+
#include <iomanip>
30+
#include <cstdlib>
31+
#include <fstream>
32+
#include <string>
33+
#include <stdio.h>
34+
35+
using namespace std;
36+
37+
//************************************************************************************************************
38+
// Global Declarations
39+
40+
41+
// file input object
42+
ifstream inFile ("semgrades4.txt"); // input file stream variable
43+
void testTest (ifstream&);
44+
const int totalClasses = 30;
45+
const int totalQuizzes = 6;
46+
const int maxProjects = 6;
47+
const int totalExams = 2;
48+
49+
//functional prototype
50+
int getInt(ifstream&);
51+
52+
// struct
53+
class Student // class for class variable
54+
{
55+
public:
56+
string studentName; // Student name variable
57+
int quizGrades[totalQuizzes]; // quiz grades array
58+
int projGrades[maxProjects]; // project grades array
59+
int totalProjects;
60+
int examGrades[totalExams];
61+
int absences;
62+
float courseAvg;
63+
float adjustedAvg;
64+
65+
public:
66+
void readIn (ifstream &inFile); // read in function
67+
void printAll ();
68+
69+
};
70+
// class variable defined within main
71+
72+
//**************************************************************************************************************
73+
// Local/ Main
74+
75+
int main() {
76+
77+
testTest (inFile);
78+
79+
Student sOne = Student();
80+
81+
while (inFile.peek() != EOF){
82+
sOne.readIn(inFile);
83+
sOne.printAll();
84+
}
85+
86+
87+
88+
return 0;
89+
90+
}
91+
//****************************************************************************************
92+
93+
// Function definitions
94+
95+
void testTest (ifstream &infile){
96+
97+
// inFile test
98+
if (inFile.fail()){
99+
cout << "Error has occured, file not sucessfully opened. " << endl;
100+
}
101+
else {
102+
cout << "File has opened sucessfully. " << endl ;
103+
}
104+
105+
};
106+
107+
void Student::readIn (ifstream &inFile){
108+
109+
int i, j;
110+
getline(inFile, studentName);
111+
for(i = 0; i < totalQuizzes; ++i){
112+
quizGrades[i] = getInt(inFile);
113+
}
114+
for(i = 0; i < maxProjects; ++i){
115+
j = getInt(inFile);
116+
if(j == -1){
117+
totalProjects = i;
118+
i = maxProjects;
119+
}
120+
else{
121+
projGrades[i] = j;
122+
}
123+
}
124+
for(i = 0; i < totalExams; ++i){
125+
examGrades[i] = getInt(inFile);
126+
}
127+
absences = getInt(inFile);
128+
}
129+
130+
int getInt(ifstream &inFile){
131+
132+
int sign = 1;
133+
int magnitude = 0;
134+
char c;
135+
136+
inFile.get(c);
137+
while(c < '0' || c > '9'){
138+
if(c == '-'){
139+
c = inFile.peek();
140+
if(c >= '0' && c <= '9')
141+
sign = -1;
142+
}
143+
144+
inFile.get(c);
145+
}
146+
147+
while(c >= '0' && c <= '9'){
148+
magnitude *= 10;
149+
magnitude += (c - '0');
150+
inFile.get(c);
151+
}
152+
153+
return sign * magnitude;
154+
};
155+
156+
void Student:: printAll(){
157+
158+
cout << studentName << endl;
159+
160+
int i;
161+
cout << "Quizz Grades: ";
162+
for(i = 0; i < totalQuizzes; ++i){
163+
cout << quizGrades[i] << ' ';
164+
}
165+
cout << endl;
166+
167+
cout << "Project Grades: ";
168+
for(i = 0; i < totalProjects; ++i){
169+
cout << projGrades[i] << ' ';
170+
}
171+
cout << endl;
172+
173+
cout << "Exam Grades: ";
174+
for(i = 0; i < totalExams; ++i){
175+
cout << examGrades[i] << ' ';
176+
}
177+
cout << endl;
178+
179+
cout << absences << endl;
180+
181+
};
182+

C++/C++ Summary/C++ Summary.cpp

+112
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
Activating a program
2+
/*In order to run this program, you must link all the files together through a makefile, run the files through a
3+
compiler and a linker, and then run the resulting executible file.*/
4+
5+
Linking modules/headers/etc
6+
#include <cstdlib> //#include links header and implementation files
7+
#include exampleImpl.h
8+
#include exampleImpl.cpp
9+
10+
namespaces
11+
using std::cin; //includes object from std namespace, to include all std variables use "using namespace std;"
12+
using newType = existingType; //preferred way to create type aliases
13+
typedef existingType newType; //old way to create type aliases
14+
15+
program structure
16+
void function(int parameter); /*function prototype, provides the compiler with a "name" for the function
17+
variable types: char, int, double, bool, void, nullptr
18+
type casting: (type) variable*/ IMPORTANT!!! In C++, the explicit keyword is your best friend. Put it in front of every variable possible.
19+
20+
int main(int argc, char* argv[]){ //every program must have one and only one main function. char* argv[] is an array of char pointers
21+
}
22+
23+
operators //Can be overloaded: returnType leftOperand/Namespace::operator=( type rightOperand )
24+
assignment: =
25+
arithmetic; +, -, *, /, %
26+
bitwise: &, |, ^, ~, <<, >>
27+
compound assignment: +=, -=, *=, /=, %=, &=, ^=, |=, <<=, >>=
28+
in/decrement: ++, --
29+
comparison: ==, !=, <, >, <=, >=
30+
logical: !, &&, ||
31+
conditional: statement ? ifTrue : ifFalse
32+
Special operators: sizeof(x), typedef(x)
33+
34+
Input from Standard input
35+
cin >> stringVariable;
36+
37+
Output to standard output
38+
cout << "String";
39+
40+
Input from file
41+
#include <iostream>
42+
#include <fstream>
43+
ifstream myFile;
44+
myFile.open("path/to/file");
45+
if(myFile.is_open){
46+
while(!myFile.eof()){
47+
myFile >> stringVar;
48+
//do things
49+
}
50+
}
51+
52+
Output to file
53+
ofstream myFile;
54+
//same as above
55+
myFile << stringVar;
56+
}
57+
myFile.close;
58+
59+
variable scope: package, file, function, block, class/"static"
60+
Flow control: if, else, switch
61+
Repetition: while, do while, for, for-each
62+
Functions: pass by value, pass by reference
63+
overloading: returnType namespace::sameFunctionName( different parameters){};
64+
65+
Array initialization// elementVariable = arrayName[index];
66+
type foo[number];
67+
type bar[number] = {element1, element2, etc...};
68+
69+
//C style arrays are not self aware, so if you pass one as a function argument, you should also pass the size of the array.
70+
71+
Strings: finding substrings, concatenation, comparison
72+
73+
Objects: initialization, modification, deletion
74+
object = new constructor() or struct //struct structure: struct name {dataType dataMember, otherType otherMember, etc... }
75+
delete object; //calls object's destructor
76+
77+
Structs
78+
unions: different types sharing the same memory address
79+
enum struct: array of constants
80+
81+
Standard objects: vectors, lists, stacks, deques, queques, maps, sets
82+
83+
Inheritance: multiple inheritance //covered in example.h
84+
polymorphism: /*using a baseClass pointer aimed at a derivedClass, you can call any method that the baseClass has. If the method has been overwritten by the derivedClass, then that
85+
behavior will be implemented instead*/ C++'s virtual method = java's abstract method. If a virtual method =0 / has no implementation, then the class is abstract
86+
87+
Exception Handling:
88+
try, catch(exception e), catch(...)
89+
90+
Special Features:
91+
generics
92+
template <class T>
93+
returnType function(T arg){ //classes can also be templates: class Example{T genericDataMember; }
94+
}
95+
96+
pointers //variables that contain memory addresses of variables or objects
97+
object *pointer = &object; //& is an operator which returns the address of object
98+
objectsAddress = pointer;
99+
object = *pointer;
100+
object **seriousPointer = &pointer; //just keep adding asterisks
101+
returnType (*functionPointer) (parameters) = functionName; //pointers can point to functions as well
102+
pointer = null; //killing a pointer
103+
104+
const
105+
const int = 1; //constant variables can not be modified after initialization
106+
const int* const pointer = &x; //constant pointer to const int. either const could be removed
107+
108+
type-casting //Since C++ is strongly typed, type casting is required more often then not
109+
dynamic_cast <newType> (oldType) //Strictest cast. Uses runtime type info to confirm type safety
110+
static_cast same //Allows casts between any related classes. No safety checks
111+
reinterpret_cast same //Allows any type of casting. Dangerous
112+
const_cast same //Should only be used to make a non constant variable constant so said variable can be used with constant functions

C++/C++ Summary/C++ Summary.hpp

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#ifndef EXAMPLE_H //a preprocessor directive to minimize excess linking
2+
#define EXAMPLE_H //other useful directive include #ifdef, #if, #else, #elif, and #undef
3+
4+
/*classes can also be const, which means its data members are read only once initialized*/ derivedClass Example: public baseClass, public otherBaseClass?
5+
//multiple inheritance is possible in C++ although not recommended
6+
{
7+
friend objects or functions;
8+
public:
9+
function prototypes and data members; //data members and methods can be referenced by either class.name or by class->name
10+
Example(); //Constructor
11+
~Example(); //Destructor
12+
protected:
13+
same;
14+
private:
15+
same;
16+
memberObject;
17+
returnType privateMethod(parameters); //methods can also be const, which means they do not modify any data members
18+
};
19+
20+
/*Every class has 6 implicit methods: constructor (C::C()), destructor (C::~C()),
21+
copy constructor (C::C(const C)), copy assignment (C& operator= (const C)), move constructor (C::C(C&&)),
22+
and move assignment (C& operator= (C&&)). These methods can be explicitly modified, defaulted, or deleted.*/
23+
24+
#endif

0 commit comments

Comments
 (0)