for Robot Artificial Inteligence

10. PDF FILES Manipulations

|

  • Please install PyPDF2 which is a common python library to work with PDF files.
  • The library can be used to read text from PDF files
  • You can install the library as follows: pip install PyPDF2

Extract information From A PDF

from PyPDF2 import PdfFileWriter, PdfFileReader
#this is the module how to write or reader in python
# two class we need
# similar to CSV files operation
# Read it as a binary files
f = open('Harvard_Business_School.pdf', 'rb')
# rb is read binary means
# Create a PDF reader object
read_pdf = PdfFileReader(f)
# obtain some document information
read_pdf.getDocumentInfo()
{'/Author': 'Barlow, Andrew Jonathan',
 '/Company': 'Harvard University',
 '/CreationDate': "D:20180817171357-04'00'",
 '/Creator': 'Acrobat PDFMaker 18 for Word',
 '/ModDate': "D:20180817171437-04'00'",
 '/Producer': 'Adobe PDF Library 15.0',
 '/SourceModified': 'D:20180817211351',
 '/Title': 'I'}
# apply the Number of pages attribute method to get the number of pages
read_pdf.numPages
# how many page we have read_pdf.numPages
# 8
# Grab any page
sample_page_text = read_pdf.getPage(2).extractText()
# extracttext out of page
# first page is it started from '0' in python
'IS \nBUSINESS \nSCHOOL \nRIGHT FOR \nYOU?\n Graduates of \nMBA \nprograms can be found in almost any type of organization. Business school will \nprepare you to create or lead an organization, manage resources, develop effective operational \nstrategies, and more. \nOnce \nadmitted, r\nequired coursework typically include\ns: Organizational \nBehavior, Marketing, Accounting, Finance, Strategy\n, \nand Operations Management. This is followed \nby elective coursework that allows the student to customize their experience. Some students \n\ncon\nsider an MBA as essential for advancement to a management role while others will use it as a \n\nmeans to change careers. As an undergraduate student, it is unlikely that you will be admitted to \n\nenter directly into an MBA program without first working for a fe\nw years. This period of \n\nemployment will give you time to think about your long term goals and help you determine if a \n\ngraduate degree is appropriate.\n Informational \nmeetings\n Talking with\n people (with or without MBAs) currently working in\n field\ns that inter\nest you\n can be \nextremely helpful as you consider your \nfuture career \noptions.\n Be sure to ask:\n How is an \nMBA viewed by the industry\n?Will an MBA improve your chances of being hired and moving ahead\n?If that person has an MBA, ask about their experience in the program they attended\nWhat was most helpful for you as you prepared your application?\nYour conversation can help you put into context how applicable the program will be to your career \n\ngoals. Also, speak with current students or those who have recently \ncompleted an MBA program. \nInquire about their experience in the program and how it has i\nmpact\ned their careers.\n What should you do to prepare for business school?\n There™s no magic formula for\n the perfect undergraduate conce\nntration\n, set of academic \nachievements, pre\n-MBA work experience\n, \nextracurricular accomplishments, essays\n, interviews, or \nrecommendation\ns. Nor is there a common \n\ncareer goal or industry in which you can \n\naspire to work. What MBAs have in common is \n\nthey find opportunities to take initiative, they \n\nare motivated, have a strong awareness of \n\nthemselves, and have a desire to learn and \n\ngrow.\n  \nBusiness schools tend to focus on impact \nmore than scale. Make sure, therefore, that the \n\nacademic and extracurricular choices you \n\nmake truly reflect your interests, demonstrate initiative, and give you opportunities to play a \n\nleadership role in the organization. A strong undergraduate academic record and GMAT (or \n\npossibly GRE) score are\n also\n important parts of your a\npplication to business school. Many sc\nhools \nallow you to sit in on a class to gain insight into what a typical course looks like. Take advantage of \n\nthis opportunity!\n Business schools look for leaders. In \nwhat ways have you demonstrated \ninitiative or translated a vision into a \n\nreality? Bear in mind that it™s not about \n\nthe size of your accomplishment, but the \npassion with which you invest in and \npursue your goals. \n'
f.close()

Copy A single page and put it in a newly created PDF

# Read a sample page
f = open('Harvard_Business_School.pdf', 'rb')
read_pdf = PdfFileReader(f)
sample_page = read_pdf.getPage(4) # we got page
# Create a writer object
write_pdf = PdfFileWriter()
write_pdf.addPage(sample_page)
#write_pdf = PdfFileWriter() this mean write_pdf is nothing.
#write_pdf.addPage(sample_page) means that input selected page into nothing
# open a newly created file
pdf_output = open('Harvard_New.pdf', 'wb') #writing porpuse like create new file
write_pdf.write(pdf_output) # write_pdf contento input created from pdf_output
pdf_output.close() # Close the new file
f.close() # close the source file

ROTATE PDFS AND WRITE THEM TO A NEW PDF

# Open the Source file
f = open('Harvard_Business_School.pdf', 'rb')
read_pdf = PdfFileReader(f)

# Create a writer object
write_pdf = PdfFileWriter() # we written anything yet

# Read a page and rotate it
rotated_page = read_pdf.getPage(2).rotateClockwise(90)

# Add the rotated page to the writer object
# PLEASE DO NOT FOREGET THAT 'P' is uppercase!
write_pdf.addPage(rotated_page)

# Save the writer object somewhere!
pdf_output = open('Harvard_New_rotated.pdf', 'wb')
write_pdf.write(pdf_output)
pdf_output.close() # Close the new file
f.close() # Close the new file

READ MULTIPLE PAGES

f = open('Harvard_Business_School.pdf', 'rb')
read_pdf = PdfFileReader(f)

pdf_text_all = [] # Create an empty list to hold the data
num_pages = read_pdf.numPages # this is how many page they are obtained

num_pages # 8
for page in range(num_pages): # range(8) means that to make (0,1,2,3,4,5,6,7) like number step by step
    one_page_text = read_pdf.getPage(page).extractText()
    pdf_text_all.append(one_page_text)
len(pdf_text_all)
# 8
pdf_text_all # Every single page summarized in a list!
'Undergraduate Resource Series\nO˜ce of Career Services | 54 Dunster Street     \nHarvard University | Faculty of Arts and Sciences | 617.495.2595\nwww.ocs.fas.harvard.edu\nOCSAPPLYING  TO \nBUSINESS  SCHOOLPhoto: Harvard University News O˜ce\n',
 '© 201 President and Fellows of Harvard CollegeAll rights reserved.\nNo part \nof this publication may be reproduc\ned in any wa\ny without the express written \npermission of the Harvard University Faculty of Arts & Sciences Office of Career Services.08/1O˜ce of Career Services\nHarvard University\n\nFaculty of Arts & Sciences\n\nCambridge, MA 02138\n\nPhone: (617) 495-2595\n\nwww.ocs.fas.harvard.edu\n',
 'IS \nBUSINESS \nSCHOOL \nRIGHT FOR \nYOU?\n Graduates of \nMBA \nprograms can be found in almost any type of organization. Business school will \nprepare you to create or lead an organization, manage resources, develop effective operational \nstrategies, and more. \nOnce \nadmitted, r\nequired coursework typically include\ns: Organizational \nBehavior, Marketing, Accounting, Finance, Strategy\n, \nand Operations Management. This is followed \nby elective coursework that allows the student to customize their experience. Some students \n\ncon\nsider an MBA as essential for advancement to a management role while others will use it as a \n\nmeans to change careers. As an undergraduate student, it is unlikely that you will be admitted to \n\nenter directly into an MBA program without first working for a fe\nw years. This period of \n\nemployment will give you time to think about your long term goals and help you determine if a \n\ngraduate degree is appropriate.\n Informational \nmeetings\n Talking with\n people (with or without MBAs) currently working in\n field\ns that inter\nest you\n can be \nextremely helpful as you consider your \nfuture career \noptions.\n Be sure to ask:\n How is an \nMBA viewed by the industry\n?Will an MBA improve your chances of being hired and moving ahead\n?If that person has an MBA, ask about their experience in the program they attended\nWhat was most helpful for you as you prepared your application?\nYour conversation can help you put into context how applicable the program will be to your career \n\ngoals. Also, speak with current students or those who have rec

WaterMark to PDF

from PyPDF2 import PdfFileWriter, PdfFileReader

# Open watermark
f = open('watermark_conf_2.pdf', 'rb')
read_watermark = PdfFileReader(f)
watermark_page = read_watermark.getPage(0)

# Open file to be watermarked
f = open('Harvard_Business_School.pdf', 'rb')
read_pdf = PdfFileReader(f)


# Create a writer object
write_pdf = PdfFileWriter()

# watermark all pages
num_pages = read_pdf.getNumPages()
num_pages
# 8
for page in range(num_pages):
    single_page = read_pdf.getPage(page)
    single_page.mergePage(watermark_page) # merge watermark_page into read_pdf.file
    write_pdf.addPage(single_page)


# Save the writer object somewhere!
pdf_output = open('Harvard_watermarked.pdf', 'wb')
#wb is the writing funcition.
write_pdf.write(pdf_output)
pdf_output.close() # Close the new file
f.close() # Close the new file    

Comment  Read more

10. Pointer 응용 (Lottery)

|

Exercise

#include <iostream>
#include <cstdlib>

using namespace std;

int *createArray(int);

void swapTwoValues(int*, int*);

void printArrayValues(int[], int);

void bubbleSort(int[], int, int = 1);
void selectionSort(int[], int, int = 1);


int main ()
{

    int sizeOfArray;
    cout << "Input the size of the array to sort: ";
    cin >> sizeOfArray;

    int *a = createArray(sizeOfArray);

    printArrayValues(a, sizeOfArray);

    int orderOfSequence;
    cout << endl << "Sort Ascending - 1, Descending - 2: ";
    cin >> orderOfSequence;

    if (orderOfSequence != 2)
        orderOfSequence = 1;

    char sortChoice;
    cout << "Bubble Sort - B or b, Selection Sort - S or s: ";
    cin >> sortChoice;

    if (sortChoice != 'S' || sortChoice != 's')
        sortChoice = 'B';

    if (sortChoice == 'B' || sortChoice == 'b')
    {
        bubbleSort(a, sizeOfArray, orderOfSequence);
    }
    else if (sortChoice == 'S' || sortChoice == 's')
    {
        selectionSort(a, sizeOfArray, orderOfSequence);
    }

    delete[] a;
    return 0;
}

int *createArray(int sizeOfArray)
{
    int* newArray = new int[sizeOfArray];

    for (int i = 0; i < sizeOfArray; i++)
    {
        newArray[i] = rand()%1500;
    }

    return newArray;
}

void swapTwoValues(int* firstValue, int* secondValue)
{
    int temporaryVariable;

    temporaryVariable = *firstValue;
    *firstValue = *secondValue;
    *secondValue = temporaryVariable;
}

void printArrayValues(int arrayToPrint[], int sizeOfArray)
{
    for (int i = 0; i < sizeOfArray; i++)
    {
        cout << "Array[" << i << "] = " << arrayToPrint[i] << endl;
    }
    cout << endl;
}

void bubbleSort(int arrayToSort[], int sizeOfArray, int orderOfSequence)
{
    for (int i = 0; i < sizeOfArray-1; i++)
    {
        for (int j = 0; j < sizeOfArray-1; j++)
        {
            if (orderOfSequence == 1 && arrayToSort[j] > arrayToSort[j+1])
            {
                    swapTwoValues(arrayToSort+j, arrayToSort+j+1);
            }
            else if (orderOfSequence == 2 && arrayToSort[j] < arrayToSort[j+1])
            {
                    swapTwoValues(arrayToSort+j, arrayToSort+j+1);
            }
        }
    }
    printArrayValues(arrayToSort, sizeOfArray);
}

void selectionSort(int arrayToSort[], int sizeOfArray, int orderOfSequence)
{
    int limitIndex;
    for (int i = 0; i < sizeOfArray; i++)
    {
        limitIndex = i;
        for (int j = i; j < sizeOfArray; j++)
        {
            if (orderOfSequence == 1 && arrayToSort[j] < arrayToSort[limitIndex])
            {
                limitIndex = j;
            }
            else if (orderOfSequence == 2 && arrayToSort[j] > arrayToSort[limitIndex])
            {
                limitIndex = j;
            }
        }
        swapTwoValues(arrayToSort+i, arrayToSort+limitIndex);
    }
    printArrayValues(arrayToSort, sizeOfArray);
}

Exercise2

#include <iostream>
#include <cstdlib>

using namespace std;

int * createArray(int);

void swapTwoValues(int*, int*);

void fillArrayWithValues(int[], int);
void printArrayValues(int[], int);

void bubbleSort(int[], int, int = 1);
void selectionSort(int[], int, int = 1);


int main ()
{

    int sizeOfArray;
    cout << "Input the size of the array to sort: ";
    cin >> sizeOfArray;

    int* a = createArray(sizeOfArray);

    fillArrayWithValues(a, sizeOfArray);
    printArrayValues(a, sizeOfArray);

    int orderOfSequence;
    cout << endl << "Sort Ascending - 1, Descending - 2: ";
    cin >> orderOfSequence;

    if (orderOfSequence != 2)
        orderOfSequence = 1;

    char sortChoice;
    cout << "Bubble Sort - B or b, Selection Sort - S or s: ";
    cin >> sortChoice;

    if (sortChoice != 'S' || sortChoice != 's')
        sortChoice = 'B';

    if (sortChoice == 'B' || sortChoice == 'b')
    {
        bubbleSort(a, sizeOfArray, orderOfSequence);
    }
    else if (sortChoice == 'S' || sortChoice == 's')
    {
        selectionSort(a, sizeOfArray, orderOfSequence);
    }

    delete[] a;
    return 0;
}

int * createArray(int sizeOfArray)
{
    int* newArray = new int[sizeOfArray];

    return newArray;
}

void swapTwoValues(int* firstValue, int* secondValue)
{
    int temporaryVariable;

    temporaryVariable = *firstValue;
    *firstValue = *secondValue;
    *secondValue = temporaryVariable;
}

void fillArrayWithValues(int arrayToFill[], int sizeOfArray)
{
    for (int i = 0; i < sizeOfArray; i++)
    {
        cout << "Enter " << i+1 << " element: ";
        cin >> arrayToFill[i];
    }
    system("cls");
}

void printArrayValues(int arrayToPrint[], int sizeOfArray)
{
    for (int i = 0; i < sizeOfArray; i++)
    {
        cout << "Array[" << i << "] = " << arrayToPrint[i] << endl;
    }
    cout << endl;
}

void bubbleSort(int arrayToSort[], int sizeOfArray, int orderOfSequence)
{
    for (int i = 0; i < sizeOfArray-1; i++)
    {
        for (int j = 0; j < sizeOfArray-1; j++)
        {
            if (orderOfSequence == 1 && arrayToSort[j] > arrayToSort[j+1])
            {
                    swapTwoValues(arrayToSort+j, arrayToSort+j+1);
            }
            else if (orderOfSequence == 2 && arrayToSort[j] < arrayToSort[j+1])
            {
                    swapTwoValues(arrayToSort+j, arrayToSort+j+1);
            }
        }
    }
    printArrayValues(arrayToSort, sizeOfArray);
}

void selectionSort(int arrayToSort[], int sizeOfArray, int orderOfSequence)
{
    int limitIndex;
    for (int i = 0; i < sizeOfArray; i++)
    {
        limitIndex = i;
        for (int j = i; j < sizeOfArray; j++)
        {
            if (orderOfSequence == 1 && arrayToSort[j] < arrayToSort[limitIndex])
            {
                limitIndex = j;
            }
            else if (orderOfSequence == 2 && arrayToSort[j] > arrayToSort[limitIndex])
            {
                limitIndex = j;
            }
        }
        swapTwoValues(arrayToSort+i, arrayToSort+limitIndex);
    }
    printArrayValues(arrayToSort, sizeOfArray);
}

Exercise 3

#include <iostream>

using namespace std;

int main ()
{

    int arraySize;

    cout << "Input the size of the dynamic array you want to create: ";
    cin >> arraySize;

    int *dynamicArray = new int[arraySize];


    for (int i = 0; i < arraySize; i++)
    {
        cout << "Input " << i+1 << " number: ";
        cin >> *(dynamicArray+i);
    }

    for (int i = 0; i < arraySize; i++)
    {
        cout << "Number " << i+1 << ": " << *(dynamicArray+i) << endl;
    }

    delete []dynamicArray;


}


Comment  Read more

9. Face and Eye Detection

|

Detect Single Faces

import numpy as np
import cv2
image_c = cv2.imread('Trudeau.jpg')
image_g = cv2.cvtColor(image_c, cv2.COLOR_BGR2GRAY) # gray scale function.
#cvtColor <- means that change the color of image_c
cv2.imshow('Trudeau in Color', image_c)
cv2.imshow('Trudeau in Grayscale', image_g)
cv2.waitKey()
cv2.destroyAllWindows()
# get CascadeClassifier (trained model)
face_detection = cv2.CascadeClassifier('Haarcascades/haarcascade_frontalface_default.xml')
#path of our classifier
#cascade means that 소통하달
#haar is the developer of this
  • CascadeClassifier.detectMultiScale(input image, Scale Factor , Min Neighbours)
    • Scale Factor
      • Specifies how much reduction takes place in the image size each time during pyramiding process.
      • or 1.2, it means image is reduced by 20% each time it’s scaled.
    • Min Neighbours
      • Parameter specifying how many neighbours each candidate rectangle should have to retain it.
      • set it to a number between 3 and 6.
      • This parameter will affect the quality of the detected faces.
      • Higher value results in less detections but with higher quality.
# The face classifier returns the region of interest in a tuple
# Two points: upper left and bottom right coordinates
faces = face_detection.detectMultiScale(image_c, 1.1, 5)
# scale factor : sacle our image like smaller or large scale. like each point reduce
# 사진들을 픽셀로 쪼개서 얼굴을 인식 한다.
# min neighbors that detect around face "5" times
faces.shape
# (1, 4)
faces # coordinate of face, pixel of face loacated
# 332 x , 121 y , (208, 208) <- retangle. size of the face
faces[:,1]
#[:,1] <- list in the 1
#[:,2] <- value list in the 2
x = faces[:, 0]
y = faces[:, 1]
w = faces[:, 2]
h = faces[:, 3]

cv2.rectangle(image_c, (x,y), (x+w,y+h), (0,255,255), 3)
#x,y is top left corner.
#w+x, y+h is the bottome of right corner
#(0,255,255) yellow color
# 3 is the thickness
cv2.imshow('Single Face Detection', image_c)
cv2.waitKey(0)

cv2.destroyAllWindows()

Detect Multiple Faces

image_c = cv2.imread('Scientists.jpg')
image_g = cv2.cvtColor(image_c, cv2.COLOR_BGR2GRAY)
cv2.imshow('Scientists in Color', image_c)
cv2.waitKey()
cv2.destroyAllWindows()

cv2.imshow('Scientists in GrayScale', image_g)
cv2.waitKey()
cv2.destroyAllWindows()
# get CascadeClassifier (trained model)
face_detection = cv2.CascadeClassifier('Haarcascades/haarcascade_frontalface_default.xml')
faces = face_detection.detectMultiScale(image_c, 1.1, 5)
faces
array([[ 15, 131,  46,  46],
       [ 42,   5,  37,  37],
       [626, 149,  52,  52],
       [196, 153,  59,  59],
       [340, 157,  60,  60],
       [ 66, 161,  57,  57],
       [717, 144,  56,  56],
       [496, 149,  55,  55],
       [347, 203,  50,  50],
       [540, 104,  46,  46],
       [420, 107,  48,  48],
       [272, 112,  55,  55],
       [658, 114,  47,  47],
       [ 12, 106,  54,  54],
       [132,  31,  43,  43],
       [527,  35,  38,  38],
       [801,  35,  38,  38],
       [134, 115,  53,  53],
       [787, 115,  56,  56],
       [309,  40,  46,  46],
       [420,  56,  45,  45],
       [199,  62,  46,  46]], dtype=int32)
for (x,y,w,h) in faces:
    cv2.rectangle(image_c, (x,y), (x+w,y+h), (0,255,255), 3)
    cv2.imshow('Single Face Detection', image_c)
    cv2.waitKey(0)
#valiable get value from per array each time for      
cv2.destroyAllWindows()

Detect Eyes and Faces

image_c = cv2.imread('Trudeau.jpg')
face_classifier = cv2.CascadeClassifier('Haarcascades/haarcascade_frontalface_default.xml')
eye_classifier = cv2.CascadeClassifier('Haarcascades/haarcascade_eye.xml')
faces = face_classifier.detectMultiScale(image_c, 1.2, 5)

for (x,y,w,h) in faces:
    cv2.rectangle(image_c,(x,y),(x+w,y+h),(0,255,255), 3)
    cv2.imshow('Trudeau Face and Eyes',image_c)
    cv2.waitKey(0)

    # Select the face
    face_region = image_c[y:y+h,x:x+w]
    #y+h is hight of image
    #x+w width of my face

    eyes = eye_classifier.detectMultiScale(face_region)

    for (eyes_x, eyes_y, eyes_w,eyes_h) in eyes:
        cv2.rectangle(face_region,(eyes_x, eyes_y),(eyes_x + eyes_w, eyes_y + eyes_h), (0,255,0),3)
        cv2.imshow('Trudeau Face and Eyes',image_c)
        cv2.waitKey(0)

cv2.destroyAllWindows()

Comment  Read more

9.Data Structure & Pointer

|

Example 1

#include <iostream>

using namespace std;

struct book
{
    string author;
    string title;
    int publicationYear;
};

void setBook(book&);

int main()
{
    book book1, book2, book3;

    setBook(book1);
    setBook(book2);
    setBook(book3);

    return 0;
}

void setBook(book &bookToSet)
{
    cout << "Who is the author of the book: ";
    cin >> bookToSet.author; // kind of def in python
    cout << "What is the title of the book: ";
    cin >> bookToSet.title;
    cout << "In what year was the book published: ";
    cin >> bookToSet.publicationYear;
}

Example 2

#include <iostream>

using namespace std;

struct book
{
    string author;
    string title;
    int publicationYear;
};

void setBook(book&);
void showBook(book);

int main()
{
    book book1, book2, book3;

    setBook(book1);
    setBook(book2);
    setBook(book3);


    showBook(book1);
    showBook(book2);
    showBook(book3);
    return 0;
}

void setBook(book &bookToSet)
{
    cout << "Who is the author of the book: ";
    getline(cin, bookToSet.author);
    cout << "What is the title of the book: ";
    getline(cin, bookToSet.title);
    cout << "In what year was the book published: ";
    cin >> bookToSet.publicationYear;
    cin.ignore();
}
void showBook(book bookToShow)
{
    cout << endl << bookToShow.author <<  " " << bookToShow.title <<  " " << bookToShow.publicationYear << endl;
}

Example 3

#include <iostream>

using namespace std;

int main ()
{

    int arraySize;

    cout << "Input the size of the dynamic array you want to create: ";
    cin >> arraySize;

    int *dynamicArray = new int[arraySize];


    for (int i = 0; i < arraySize; i++)
    {
        cout << "Input " << i+1 << " number: ";
        cin >> *(dynamicArray+i);
    }

    for (int i = 0; i < arraySize; i++)
    {
        cout << "Number " << i+1 << ": " << *(dynamicArray+i) << endl;
    }

    delete []dynamicArray;


}


Example 4

#include <iostream>

using namespace std;

int main ()
{

    int a = 5;
    int *p = &a;
    int **pp = &p;

    cout << "Value of the variable a is equal to: " << a << endl;
    cout << "The address of the variable a is equal to: " << &a << endl;
    cout << "The value stored in the pointer p is equal to: " << p << endl;
    cout << "To get the value of the variable a using pointer p one has to point to the address in the pointer p, *p = " << *p << endl << endl;
    cout << "Pointer p has its own address which is: " << &p << endl;
    cout << "The value stored in the pointer pp is equal to: " << pp << endl;
    cout << "To get the value of the pointer p using pointer pp one has to point to the address in the pointer pp, *pp = " << *pp << endl;
    cout << "To get the value of he variable a using pointer pp one has to point to the address in the pointer pp and p, **pp = " << **pp << endl;

    return 0;
}

Example 5

#include <iostream>

using namespace std;

int main ()
{
    int charactersNumber;

    cout << "How many characters would you like to input: ";
    cin >> charactersNumber;

    char *characters = new char[charactersNumber];

    for (int i = 0; i < charactersNumber; i++)
    {
        cout << i+1 << " character: ";
        cin >> characters[i];
    }

    cout << "The inputted string of characters was: ";

    for (int i = 0; i < charactersNumber; i++)
    {
        cout << *(characters+i);
    }


    delete [] characters;


    return 0;
}

Example 6

#include <iostream>

using namespace std;

int main ()
{
    int arr[5];
    int *pArr = arr;

    for (int i = 0; i < 5; i++)
    {
        cout << "Input " << i+1 << " number: ";
        cin >> *(pArr++);
    }

    for (int i = 0; i < 5; i++)
    {
        cout << "Number " << i+1 << ": " << arr[i] << endl;
    }

    return 0;
}

Comment  Read more

Linux 중요한 명령어

|

1.SUDO

SuperUserDo 의미로 Permission이 제한된 작업을 할때 사용한다.

  • $sudo su

2.ls(LIST)

Folder 나 보고 싶은 Directories & files를 보고 싶을 때 사용 한다.

  • /home$ ls

3.CD(Changing Directory)

터미널에서 자주 쓰는 명령어로 디렉토리를 이동할 때 사용한다.

  • cd some Directories

    example : /home$ cd url <- url 디렉토리로 이동한다.

  • cd .. (이전 디렉토리로 이동한다.)

4.mkdir(Make Directory)

폴더를 생성할 때 쓰인다.

  • ~$ mkdir folderName

5.cp(Copy-and-paste)

터미널로 부터 폴더나 파일들을 복사하고 붙여 넣을 때 쓰인다.

  • ~$ cp src des (src를 복사하여 des에다가 붙여 넣는다.)

    Permission이 있는 파일 들은 Sudo 명령어를 사용하여 cp 명령어를 사용한다.

6.rm(Remove)

삭제 명령어로 원하는 파일이나 폴더를 삭제할 수 있다.

  • ~$ rm myfile.txt

7.apt-get

Advanced Packaging Tool(APT) Package 매니저로 소프트웨어를 설치하는데 사용한다.

  • ~$ Sudo apt−get update

8.Grep

찾고자 하는 파일의 위치나 경로를 모를 때 사용 한다.

  • ~$ grep user /etc/passwd

9.cat(concatenate)

cat명령어는 text 파일이나 코드들의 내용물을 볼때 터미널에서 사용된다.

  • ~$ cat CMakeLists.txt

    root@server:/test/t1# cat hello.txt Hi, This is for testing only

10.poweroff

사용하고 있는 termnial 창을 종료 시킬때 사용한다.

  • $ sudo poweroff

11.pwd

현재 디렉토리의 경로가 어떻게 되어있는지 print해서 터미널에 보여준다

  • $ pwd

12.mv(move/rename)

파일을 다른 폴더로 옮기거나 이름을 바꿀때 사용 된다.

root@server:/test# mv t1/* t2
root@server:/test# mv t2 test2
root@server:/test# ls
t1 test2

13. rmdir(Remove Directory)

말 그대로 디렉토리 제거하는데 쓰이는 명령어다.

root@server:/test# ls
t1 test2
root@server:/test# rmdir t1
root@server:/test# ls
test2

14.touch(Create blank file)

touch 명령어는 파일을 만들어 내는데 쓰인다.

root@server:/test/test2# touch empty.txt
root@server:/test/test2# ls
empty.txt hello.txt

15.free(check free ram)

컴퓨터 안에 사용할 수 있는 free ram을 체크한다.

root@server:/test/test2# free
total used free shared buff/cache available
2097152 598076 1417768 232288 81308 1424127

16.df(Disk Space)

컴퓨터 디스크 용량을 확인하는데 사용한다.

root@server:/test# df -h Filesystem Size Used Avail Use% Mounted on
/dev/simfs 95G 2.3G 93G 3% /
devtmpfs 1.0G 0 1.0G 0% /dev
tmpfs 1.0G 0 1.0G 0% /dev/shm
tmpfs 1.0G 99M 926M 10% /run
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 1.0G 0 1.0G 0% /sys/fs/cgroup
none 1.0G 0 1.0G 0% /run/shm

17.chmod (change Permission)

파일의 Permission 상태를 쓰기가 가능하게 혹은 오직 읽기만 가능하게 변화 시켜준다.

root@server:/test# chmod 755 test2 (755는 폴더 안에 있는 모든 파일의 permission을 사용할 수 있게 바꿔준다.)
root@server:/test# chmod + test.txt (“+”한가지 파일의 permission을 사용할 수 있게 바꿔준다.)

18.du(Directory usage)

디렉토리의 용량들을 확인할 수 있다.

root@server:/test# du
8 ./test2
12 .

Comment  Read more