Skip to content
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
4 changes: 4 additions & 0 deletions PA1/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
all:
g++ 171044071_salih_tangel.cpp -o run
do:
g++ vector2d_2.cpp -o run
Binary file added PA1/PA1.pdf
Binary file not shown.
183 changes: 183 additions & 0 deletions PA1/salih_tangel_171044071.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;
const int MAX = 10; //it must be max 10 if it would be unique
int is_it_error_1(char one[MAX],char two[MAX],int digit){ //check is it error 1
int i=0;
if(strlen(one)!=strlen(two))
return 0;
else
return 1;
}
int is_it_same(char one[MAX],char two[MAX],int digit){ //check is it finish
int i=0;
for(;i<digit;i++){
if(one[i]!=two[i])
return 0;
}
return 1;
}
int check(char one[MAX],char character,int digit){ //check for random number
int i=0;
for(;i<digit;i++){
if(one[i]==character)
return 0;
}
return 1;
}
int is_it_error_0(char one[MAX], int digit) { //check is it error 0
int i = 0, j = digit;
if (one[i] == '0') return 0;
for (; i < digit; i++) {
for(j=0;j<digit;j++){
if (one[i] == one[j] && i!=j || one[i] == '-')
return 0;
}
}
if(digit > 9)
return 0;
return 1;
}
int fun_find_exact(char one[MAX], char two[MAX], int digit) { //find hint exact num
int i = 0, k = 0;
for (i = 0; i < digit; i++) {
if (one[i] == two[i]) k++;
}
return k;
}
int fun_find_wrong_placeses(char one[MAX], char two[MAX], int digit) { //find hint wrong places
int i = 0, j = 0, k = 0;
for (; i < digit; i++) {
for (j = 0; j < digit; j++) {
if (one[i] == two[j] && i != j) k++;
}
}
return k;
}
int is_it_not_int(char one[MAX]) { //check is it integer
int i = 0;
while (one[i] != '\0') {
if (!(one[i] >=48 && one[i]<=57 || one[i]== 45) ) { //between ascii value of 0 and 9 and do not touch negatif value

return 0;
}
i++;
}
return 1;
}
int find_digit(int first, int second) { //find digit
int i = 1; int j = 1; while (first != 0 && second != 0) {
first /= 10;
second /= 10;
if (first != 0) i++;
if (second != 0) j++;
}
if (i == j)
return i;
else {
return 0;
}
}
int main(int argc, char *argv[]) {
int new_num; //int version of user num
char user_num[MAX]; //user num
char random_num[MAX]; //random generate num
int exact = 0; //exact hint
int misplaced = 0; //misplaced hint
int game_counter = 0; //game counter for 100 times
int digit, i; //digit numand i for counter

if (0 == strcmp(argv[1], "-r")) { //random num game
if(atoi(argv[2]) > 9){ //for digit control
cout << "Error 0" << endl;
return 1;
}
do {
cin >> user_num; //take user num
new_num =atoi(user_num); // convert string to the int number
digit = find_digit(new_num,new_num); // find and return digit of numbers

srand(time(0));
random_num[0]=(rand() %9+1)+'0';//first digit zero case

for (i =1; i < atoi(argv[2]); i++) { //random num part
int flag=0;
while(!flag){
char num=rand()%10 +'0';
if(check(random_num,num,i)){
random_num[i]=num;
flag=1;
}
}
}
random_num[i] = '\0'; // to see end

if (0 == is_it_not_int(user_num) ) { //these parts for error checking
cout << "Error 2" << endl;
return 1;
}
if (0 ==is_it_error_1(user_num,random_num,digit)) {
cout << "Error 1" << endl;
return 1;
}
if (0 == is_it_error_0(user_num, digit) ) {
cout << "Error 0" << endl;
return 1;
}
if(is_it_same(random_num,user_num,digit)){
cout<<"FOUND\t";
cout<<game_counter<<endl;
return 0;
}
exact=fun_find_exact(user_num,random_num,digit); //for hints
misplaced = fun_find_wrong_placeses(user_num,random_num, digit);
cout << exact <<"\t"<< misplaced << endl; //printing hints

game_counter++;
} while (game_counter != 100);
} else if (0 == strcmp(argv[1], "-u")) { //same thing just random part miss
strcpy(random_num,argv[2]); //take secret num;
new_num=atoi(random_num);
digit = find_digit(new_num,new_num); // find and return digit of numbers

if (0 == is_it_error_0(random_num, digit)) { //these statements for only for -u case
cout << "Error 0" << endl;
return 1;
}
if(0 == is_it_not_int(random_num) || digit > 9){
cout << "Error 0" << endl;
return 1;
}
new_num=0; //to we will use new_num again
do {
cin >> user_num;
cout<<"Enter A NUMBER"<<endl;
new_num =atoi(user_num); // convert string to the int number
if (0 == is_it_error_0(user_num, digit)){
cout << "Error 0" << endl;
return 1;
}
if (0 == is_it_not_int(user_num)) {
cout << "Error 2" << endl;
return 1;
}
if (0 == find_digit(new_num, atoi(random_num))) {
cout << "Error 1" << endl;
return 1;
}
if(is_it_same(random_num,user_num,digit)){
cout<<"FOUND\t";
cout<<game_counter<<endl;
return 0;
}
exact=fun_find_exact(user_num,random_num,digit);
misplaced = fun_find_wrong_placeses(user_num, random_num, digit);
cout << exact <<"\t"<< misplaced << endl;

game_counter++;
} while (game_counter != 100);
}
cout<<"FAILED\t"<<game_counter<<endl;
return 0;
}
4 changes: 4 additions & 0 deletions PA2/1.ppm
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
P3
4 4
120
0 0 0 50 0 0 0 0 0 60 0 60 0 0 0 0 60 87 0 0 0 0 0 0 0 0 0 0 0 0 0 7 87 0 0 0 60 0 60 0 0 0 0 0 0 60 60 60
160 changes: 160 additions & 0 deletions PA2/171044071_salih_tangel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
#include <bits/stdc++.h>
#include <vector>
#include<string>
#include<fstream>
using namespace std;

class Image{
public:
vector<int> fun_open(string filename,vector<int> v); //open part
void fun_save(string filename2,vector<int> v); // save part
vector <int> fun_grayscale(float red,float green,float blue,vector<int> v);//graysclale working
float get_red(){
return red;
}
float get_blue(){
return blue;
}
float get_green(){
return green;
}
string firstline; //for a3
string secondline; //for 4 3
string thirdline;
string fourthline; //for 255
private:
float red;//for float varibles
float green;
float blue;
};
vector<int> Image :: fun_open(string filename,vector<int> v){
int num=0;
int i=0;
cin>>filename;
ifstream myfile;
myfile.open (filename);
if (!myfile) { //error check
cerr << "Unable to open file datafile.txt";
exit(1); // call system to stop
}
myfile>>firstline;
myfile>>secondline;
myfile>>thirdline;
myfile>>fourthline;
while(myfile>>num){
v.push_back(num);
}
myfile.close();
return v;
}
void Image :: fun_save(string filename2,vector<int> v){ //not working part
int i=0;
int counter=0;
ofstream newfile;
cin>>filename2;
newfile.open(filename2);
if (!newfile.is_open()) {
cerr << "Unable to open file datafile.txt";
exit(1); // call system to stop
}
newfile<<firstline<<endl;
newfile<<secondline<<endl;
newfile<<thirdline<<endl;
newfile<<fourthline<<endl;
for(;i<v.size();i++)
{
if(counter%3==0)
newfile<<" ";
if(i%12==0){newfile<<endl;}
newfile<<v[i];
newfile<<" ";
counter++;
}
newfile.close();
}
vector<int> Image :: fun_grayscale(float red,float green,float blue,vector<int> v){
bool exit2=false;
int i=0;
string record2;
//for(i=0;i<v.size();i++)cout<<v[i] ;
do{
cout<<"enter float numbers[0,1)"<<endl;
cin>>red>>green>>blue;
if(red<1 && red>=0 && green<1 && green>=0 && blue<1 &&blue>=0)
exit2=false;
else{
cout<<"wrong num"<<endl;
exit2=true;
}
}while(exit2);

for(i=0;i<v.size();i++){ //sorun cikabilir burda
if(i%3==1){
v[i]*=green;
}
else if(i%3==0){
v[i]*=red;
}
else if(i%3==2){
v[i]*=blue;
}
if(v[i]>255){
v[i]=255;
}
}
//for(i=0;i<v.size();i++)cout<<v[i] ; //if you want to see it is working
return v;
}
int main() {
// Assign vector
vector<int> v;
bool exit = true;
int choice;
int choice2;
string filename;
string filename2;
Image x;
do {
cout << "Main Menu" << endl
<< "0-Exit" << endl
<< "1-Open An Image(D)" << endl
<< "2-Save Image Data(D)" << endl
<< "3-Scripts(D)" << endl;
cin >> choice;
if (choice == 0)
exit = false;
else if (choice == 1) {
cout << "OPEN AN IMAGE MENU" << endl
<< "0 - UP" << endl
<< "1 - Enter The Name Of The Image File" << endl;
cin >> choice2;
if (choice2 == 0){} else if (choice2 == 1){
v=x.fun_open(filename,v);
}
} else if (choice == 2) {
cout << "SAVE IMAGE DATA MENU" << endl
<< "0 - UP" << endl
<< "1 - Enter A File Name" << endl;
cin >> choice2;
if (choice2 == 0){} else if (choice2 == 1){
x.fun_save(filename2,v);
return 1;
}
} else if (choice == 3) {
cout << "SCRIPTS MENU" << endl
<< "0 - UP" << endl
<< "1 - Convert To Grayscale(D)" << endl;
cin >> choice2;
if (choice2 == 0){} else if (choice2 == 1) {
cout<<"CONVERT TO GRAYSCALE MENU"<<endl
<<"0 - UP"<<endl
<<"1 - Enter Coefficients For RED GREEN And BLUE Channels."<<endl;
cin >> choice2;
if (choice2 == 0){} else if (choice2 == 1){
v=x.fun_grayscale(x.get_red(),x.get_green(),x.get_blue(),v);
}
}
}
} while (exit);
}

4 changes: 4 additions & 0 deletions PA2/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
all:
g++ 171044071_salih_tangel.cpp -o run
do:
g++ vector2d_2.cpp -o run
Binary file added PA2/run
Binary file not shown.
8 changes: 8 additions & 0 deletions PA3/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
all:
g++ -g salih_tangel_171044071.cpp -o run
do:
g++ issue.cpp -o run
delete:
rm -rf 1.cpp
segment:
valgrind -v ./run
Binary file added PA3/a.out
Binary file not shown.
9 changes: 9 additions & 0 deletions PA3/a.ppm
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
P3
4
4
120

0 0 0 5 0 0 0 0 0 6 0 6
0 0 0 0 6 8 0 0 0 0 0 0
0 0 0 0 0 0 0 0 8 0 0 0
1 0 6 0 0 0 0 0 0 6 6 6
9 changes: 9 additions & 0 deletions PA3/b.ppm
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
P3
4
4
120

0 0 0 50 0 0 0 0 0 60 0 60
0 0 0 0 60 87 0 0 0 0 0 0
0 0 0 0 0 0 0 7 87 0 0 0
60 0 60 0 0 0 0 0 0 60 60 60
Loading