기본 콘텐츠로 건너뛰기

10월, 2017의 게시물 표시

JAVA Integer to binary with 민경~~~

package java_a5; // @author hi123 import java.io.*; import java.util.Scanner;//to use scanner //import java.long.Integer; why?? public class JAVA_A5 {     public static void main(String[] args) {         Scanner scan = new Scanner(System.in);     System.out.println("Enter the integer");     int num = scan.nextInt();     //scannerObjectName.nextInt = gets int from user      System.out.println("Binary is " + Integer.toBinaryString(num));           System.out.println("Numer of 1 bits is " + Integer.bitCount(num));     } } //yeahhhh~~~~

About Bitwise Operator

AND operation (&) = true when each operand is true. OR operation (|) = true when at least one operand is true XOR operation (~) = when two operand is different, it's true Bitwise Compliment = 보수연산. changes the absolute value to opposite. Left Shift = move bites as much as operand to left  ex) a = 0011 1100  a<<2 = 1111 Right Shift = to right  ex) a>>2 = 1111 Unsiged Right Shift (>>>) = unsigned shift operator  fill zero in leftmost bit and do shift From A6 notification //im  not sure for unsigned shift operator but do not wanna work on it now ^^ will come back when i want Chao!!

JAVA exercise 0610

//@writer Min import java.util.Scanner; public class NewClass {     public static void main(String[] args){         Scanner scan = new Scanner (System.in);                 System.out.println("Enter your age as an integer");                 while(! scan.hasNextInt() ){ //hasNextInt = returns 1 when the scanner gets next as int             String garbage = scan.nextLine( );//it calls the object scan, activate scanning line             //gets next line of input, since the data type is STRING!!             System.out.println("\n Enter as INTEGER please");         }       int age =   scan.nextInt( );             System.out.println("Your age is " + age);     } } //어예~~!!!

JAVA exercise 0601

//package exercise; import java.util.Scanner; // @author Min public class Exercise {     /**      * @param args the command line arguments      */     public static void main(String[] args) {      final int SENTINEL = -1;      int number;           Scanner scan = new Scanner(System.in); //Scanner() << in () there must be method to use through or exact variable to use      //declaring Scanner object, the name is scan, taking System.in as parameter      System.out.println("Enter an integer, -1 to end");           number = scan.nextInt();      //it calls memberfuntion of scan, it takse nextint      while(number != SENTINEL){          System.out.println(number);                   System.out.println("Enter an integer, -1 to end");          number = scan.nextInt();      }      System.out.println("Sentinel vaule detected. goodbye!");     }     } //Hello JAVA!!! sorry to hate you but let's be friend from now!!

C++ A6 submitted file

#include <iostream> #include <random> #include <iomanip> #include <chrono> #include <math.h> //@writer 5396952 Hyeonmin LEE using namespace std; int guessNum(int , int*); int guessGame(); int main() {  while(1){         if (guessGame() == -1){             break;         }     } return 0; } int guessNum(int number) { int count = 0; int input = 1;  while(1) {   count ++;      cin >> input;   if(!cin || !(input <=1000 && input >= 1)) {          cin.clear();          cin.ignore(1001, '\n');          cout << "Invalid data type or out of range!" << endl;    cout << "Please enter right value." << endl;      }       if (input < number) {          cout << "Too low. Try again." << endl;   };      if (input > number) {         cout << "Too high. Try again." << endl;      }         if(input == number){     

C++ fg0610

#include <iostream> #include <iomanip>//able to use setw #include <random>//contains random number generate feature in c++11 #include <ctime> using namespace std; int main(){  default_random_engine engine{(static_cast <unsigned int> (time (0)))};// time(0) is same with time(NULL)  //static cast makes the variable to keep the same data type through whole program.  //engine class generates random number.  uniform_int_distribution <unsigned int>randomInt{1 , 6};  //uniform_int_distribution makes set of random number's distribution between.  char wait;  for (unsigned int count = 1; count <= 10; count++){   cout << setw(10) << randomInt(engine);     if(count != 0 && count %5 == 0){    cout << endl;   }  }  cin >> wait;   return 0;  }

C++ A5 submitted header file

#include <cmath> class FindPytha{  private :  double sqrHypo = 0;  double check = 0;  double hypo = 0;  public :   double getSqrHypo(int side1, int side2){   sqrHypo = (side1 * side1) + (side2 * side2);   return sqrHypo;   }     double getHypo(double sqrHypo){    hypo = sqrt(sqrHypo);    check = round(hypo);       if(check == hypo){         return hypo;    }    else {     return 1;      };   } };

C++ A5 submitted main()

#include <iostream> #include "findPytha.h" using namespace std; //@writer 5396952 Hyeonmin LEE int main(){  FindPytha findPytha;  int side1 = 0;  int side2 = 0;  int hypo = 0;  int pythaSum = side1 +side2 + hypo;  int num = 0;  double sqrHypo = 0;  int i = 0;  int j = 0;   while(side1 <= 500){    side1++;    side2 = side1;    while(side2 <= 500){     side2 ++;     sqrHypo = findPytha.getSqrHypo(side1, side2);     hypo = findPytha.getHypo(sqrHypo);       if( hypo != 1 && hypo <= 500) {      num ++;      cout << num << ". " << side1 << " " << side2 <<" " << hypo << "\n";     }      }   } } //there was big difference to put side2=side1, i don't know why it is necessary.... still I failed to make my own loop but I'm enough proud of my header file! 질투와 승부욕은 배움의 좋은 채찍이기도 하면서 1도 도움이 안 될 때가 있다. 원래 배움이란 주고 받고 하면서 서로 배우는 것이다. 나눔에 인

C++ A4 commented header file

// Try to not put any special characters in your file names (+, spaces or such) // For class files (header and cpp file), it is a good to give them the same name as the Class (here Account.h and Account.cpp) // Think about ALWAYS putting the header code into these things, as it will protect your code from double/multi inclusion (VERY IMPORTANT!!! EVEN MORE SO IN BIGGER PROJECTS!!!) #ifndef __ACCOUNT_HPP__ #define __ACCOUNT_HPP__ #include <iostream> // BAD PRACTICE!!! AND ESPECIALLY NOT IN A HEADER PLEASE! There are A LOT of things in std, so if for example another library has a function with the same name, it can cause important problems!! // See cpp file for an alternative form //using namespace std; // Always begins with a Capital Letter!!! // Also, prefer to put your code in the appropriated cpp files, it is a lot cleaner, readable and maintainable class Account { private :  int cstNum; // cst = customer  int cstBal;//balance  int cstChrg;//charge  int cstCredit;  int cst

C++ A4 commented main()

#include <iostream> #include "C++_A4_MIN.h" //writer 5396952 Hyeonmin LEE // using namespace std; is less problematic in an cpp file, as it is restricted to only this file // I still prefer to write std::cout and such, it is more readable and at least you are sure you use the functions from the right library // Here another way to do it: using on the single components you want to use (a bit like in Java) using std::cin; using std::cout; using std::endl; int main(int argc, char** argv) {  int num = 0;  // you have to use double values here, or you wont be able to read decimals number with std::cin  double bal = 0;  double chrg = 0;  double credit = 0;  double creditLimit = 0;     // you don"t need the "class" keyword before the class name     // BONUS: you don't need the "struct" keyword either when declaring a struct in C++ (in C you need it so it is a bit confusing :x)  Account account;  while (true) {   std::cout << "Enter

C++ A4 submitted header file

#include <iostream> using namespace std; class Customer{  private :   int cstNum; // cst = customer   int cstBal;//balance   int cstChrg;//charge   int cstCredit;   int cstCreditLimit;    public :   Customer(){//consturctor    cstNum = 0;    cstBal = 0;    cstChrg = 0;    cstCredit = 0;    cstCreditLimit = 0;   }   void setNum(int num){    cstNum = num;     }     void setBal(double bal){    cstBal = (int)bal * 100;   }     void setChrg(double chrg){    cstChrg = (int)chrg * 100;   }     void setCredit(double credit){    cstCredit = (int)credit * 100;   }     void setCreditLimit(double creditLimit){    cstCreditLimit = (int)creditLimit * 100;   }     double getNewBalance(){    return ((double)cstBal - (double)cstCredit + (double)cstChrg) * 0.01;   }   void getExceed(){    double newBalance = getNewBalance();    double creditLimit = cstCreditLimit / 100.0; //explicit transform       if(creditLimit < cstCreditLimit){     std::cout << "new balance is" << new

C++ A4 submitted main()

#include <iostream> #include "customer.h" //writer 5396952 Hyeonmin LEE , helped by sascha using std::cin; using std::cout; using std::endl; int main(int argc, char** argv) {  int num = 0; //to get decimal input, will calculate it in member funtion in integer  double bal = 0;  double chrg = 0;  double credit = 0;  double creditLimit = 0;  while (1){   Customer customer;   std::cout << "Enter customer number. (or -1 to end)" << std::endl;   std::cin >> num;     if(std::cin.fail()){    return 0; //while's condtion is 1, this return 0 ends while loop   }     if(num == -1){    return 0; //end main funtion   }   customer.setNum(num);     std::cout << "Enter beginning balance." << std::endl;   std::cin >> bal;   customer.setBal(bal);     std::cout << "Enter total charge." << endl;   std::cin >> chrg;   customer.setChrg(chrg);     std::cout << "Enter total credits." <&l

Mystery...?!

#include <iostream> using namespace std; int main(){  int x = 1;  while ( x <= 10){   cout << (x % 2 == 1 ? "odd" : "even") << endl;   x++;  }  return 0; } //그댄 내 머리 위으 ㅣ우산~~!!

POWER calculator (ex04_08)

#include <iostream> using namespace std; void cal_power (); bool ask_re(); int main(){ do{  cal_power(); } while(ask_re() == true); return 0; } void cal_power(){  int i = 0;  unsigned int result = 1;  unsigned int base = 0;  unsigned int power = 0;  cout << "Enter the base." << endl;  cin >> base;  cout << "Enter the power." << endl;  cin >> power;  while (i < power){//as long as the counter is same or smaller than power   result *= base;   i ++;  }  cout << power << " power of " << base << " is" << result <<endl;//display the result } bool ask_re(){  char response;  cout << "Enter \"y\" to do again, \"n\" to end" << endl;  cin >> response;  if(response == 'y')   return true;  else if (response == 'n')   return false; //Ay YEAHHHH get swifty~~~~~~

Guessing Game~! by C++

#include <iostream> #include <cstdlib> #include <ctime> using namespace std; void guessGame(); bool isCorrect(int, int); int main(){  srand (time (0));  guessGame();  return 0; } void guessGame(){  int answer;  int guess;  char response;  do{   answer = 1 + rand() % 10; // make constant random value from 1 to 100   cout << "Guess number between 1 and 10" <<endl;   cin >> guess;       while( !isCorrect(guess, answer)) // as long as the return value is false, continue    cin >> guess; // condition itself calls funtion     cout << "\n Congrat!! wanna play new guess?" << endl;   cout << " \"y\"to start \"n\" to end" << endl;   cin >> response;   } while (response == 'y');  } //isCorrect returns true if the guess is right //if g does not equal a, displays hint bool isCorrect(int g, int a){  if (g == a){   return true;  }  if (g < a){   cout << &quo