先說最開始的get request token,我拿oAuth 1.0的官方文件和plurk API說話

文章標籤

FGOinai 發表在 痞客邦 留言(0) 人氣()

Complex.h

#ifndef COMPLEX_H
#define COMPLEX_H


class Complex {
public:
    Complex();
    Complex(double,double);
    Complex(const Complex&);
    ~Complex();
    Complex operator+(const Complex&);
    Complex operator-(const Complex&);
    Complex operator*(const Complex&);
    Complex operator/(const Complex&);
    double getReal();
    double getImginary();
    void setReal(const double);
    void setImginary(const double);
    Complex& operator++(); //perfix
    Complex operator++(int); //suffix
    Complex& operator--(); //perfix
    Complex operator--(int); //suffix
private:
    double real;
    double imginary;
};

#endif // COMPLEX_H

Complex.cpp

#include "Complex.h"

///used for calculate the result of power exponent of base
template<typename T>
T power (T arg0, const int arg1) {
    double tmp = 1;

    if (arg1 == 0) {
        return 1;
    } else if (arg1 < 0) {
        for (int i = arg1; i!=0;i++)
            tmp /= arg0;
        return tmp;
    } else {
        for (int i = arg1; i!=0;i--)
            tmp *= arg0;
        return tmp;
    }
}

Complex::Complex() {
    real = 0;
    imginary = 0;
}

Complex::Complex(double x, double y) {
    real = x;
    imginary = y;
}

Complex::Complex(const Complex& p) {
    real = p.real;
    imginary = p.imginary;
}

Complex::~Complex() {
    //dtor
}

Complex Complex::operator+ (const Complex &p) {
    Complex tmp(real+p.real, imginary+p.imginary);
    return tmp;
}

Complex Complex::operator- (const Complex &p) {
    Complex tmp(real-p.real, imginary-p.imginary);
    return tmp;
}

Complex Complex::operator* (const Complex &p) {
    Complex tmp(real*p.real - imginary*p.imginary,real*p.imginary + imginary*p.real);
    return tmp;
}

Complex Complex::operator/ (const Complex &p) {
    double real_root = power(power (p.real,2) + power(p.imginary,2),-1);
    Complex tmp((real*p.real + imginary*p.imginary)*real_root, (-real*p.imginary + imginary*p.real)*real_root);
    return tmp;
}

double Complex::getReal() {
    return real;
}

double Complex::getImginary() {
    return imginary;
}

void Complex::setReal(const double x) {
    real = x;
}

void Complex::setImginary(const double y) {
    imginary = y;
}

Complex& Complex::operator++() {
    real++;
    imginary++;

    return *this;
}

Complex Complex::operator++(int) {
    Complex tmp(real,imginary);
    real++;
    imginary++;

    return tmp;
}

///-- then LOAD VAR(CHANGED VALUE)
Complex& Complex::operator--() {
    real--;
    imginary--;

    return *this;
}

///LOAD VAR then --
Complex Complex::operator--(int) {
    Complex tmp(real,imginary);
    real--;
    imginary--;

    return tmp;
}
 

main.cpp

#include <iostream>
#include "Complex.h"
#include <iomanip>

using std::cout;
using std::fixed;
using std::setprecision;

void show(Complex& tmp);

int main () {
    Complex complex1;

    show(complex1);
    complex1.setImginary(1); ///complex1=0+i
    complex1.setReal(1); ///complex1=1+i
    show(complex1);

    Complex complex2(1,1); ///complex2=1+i
    Complex complex3(complex1+complex2); ///complex3=2+2i
    show(complex3);

    Complex complex4(complex1*complex2); ///complex4=0+2i
    show(complex4);
    Complex complex5(complex4/complex3); ///complex5=.5(1+i)
    show(complex5);

    ++complex5; ///1.5(1+i)
    show(complex5);
    complex5++; ///2.5(1+i)
    show(complex5);
    --complex5; ///1.5(1+i)
    show(complex5);
    complex5--; ///.5(1+i)
    show(complex5);

    return 0;
}

void show(Complex& tmp) {
    cout << "The complex number is " << fixed << setprecision(3) << tmp.getReal() << "+" << tmp.getImginary() << "i.\n";
}

 



基本上顯示了operator overloading是怎樣運作的....可以研究一下

 

FGOinai 發表在 痞客邦 留言(0) 人氣()

【討論】戒指運用大更新

有關這次CC大改戒指定位,隨便說一說

FGOinai 發表在 痞客邦 留言(0) 人氣()

今天HTC M7無緣無故掛掉,但其實不是沒有前兆的,這數天屏幕會突然沒反應,又或者會自動截圖之類的....
然後買了SSD,接USB外接盒電腦認不了
還有是打Maimai,Stage1就拉傷右邊胸肌和右上臂肌肉,痛死了

關於香港轉移到異世界的故事,我想在這裡寫就算了

於是明天不用上班了...

FGOinai 發表在 痞客邦 留言(0) 人氣()

這是來開發plurk app的日記,至於為甚麼已有不少現成的plurk app的情況下,我還要多造一個輪子?

因為總有些功能沒有啊!例如我有FOLLOW一些畫師,每次都要點開才能看,R18的又不能加TAG晚點再看

還有靜音和表符的問題,連線失敗的問題等……結果就讓我想自己造了

 

暫定先開發ANDROID版,在該有的功能都加了下去,並且穩定運行後,我會以Xamarin開發多平台版

FGOinai 發表在 痞客邦 留言(0) 人氣()

搞了幾天終於搞定pointer了,寫點notes

文章標籤

FGOinai 發表在 痞客邦 留言(0) 人氣()

Function 練習代碼 (20150521)

練習1 - Harmonic Numbers
練習2 - 數列平均數
練習3 - struct的練習: Volume計算
練習5 - Factorial (Recursion Function)
練習6 - Fill, show, reverse array
練習9 - Pointer to function and dynamic allocation of array


有關練習6的sort到哪去了,自然是偷懶給省掉了(炸

因為Quicksort雖然能寫,但這個等我會寫header才搞吧



練習9偷懶用了vector+pointer, 但其實只用pointer array也能做到同樣效果,只是我昨天到現在都不太舒服...沒太多心思想pointer的allocation問題



PS:對了,昨天才知道unity3D主體程式用C#/JS,不知道該高興還是不高興了...UE則是很硬的C++


文章標籤

FGOinai 發表在 痞客邦 留言(0) 人氣()

C++多維向量(vector)的動態分配

基本的想法就是是將所有方向拆散,直到只有剩下一維vector為止,以下以二維vector為例

#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main()
{

vector< vector<char> > vector1; //null 2D vector
string str; //cache
vector<char> vector1_cache;

cout << blablabla;
getline(cin,str);

for (string::iterator it=str.begin(); it != str.end(); it++) //iterator for string
//C++11 style: for (auto it=str.begin(); it != str.end(); it++)
  vector1_cache.push_back(*it);

vector1.push_back(vector1_cache); //put all data in cache into vector1

return 0;
}

 三維以上思路雷同,不過是要包多少層而已,實際操作的話如無必要也不會用上N維的vector,效率低而且容易出錯,真有需要的話應該改用非STL的matrix代替vector

文章標籤

FGOinai 發表在 痞客邦 留言(0) 人氣()

«12