int PolylineTest::readFileMoniker() { ComPtr<IStorage> pStorage; ComPtr<IStream> pStream; auto hr = StgOpenStorageEx(kMonikerFileName, STGM_READ | STGM_SHARE_EXCLUSIVE | STGM_DIRECT, STGFMT_STORAGE, 0, NULL, 0, IID_IStorage, (void**)&pStorage); if (FAILED(hr)) return hr; hr = pStorage->OpenStream(kStreamName, NULL, STGM_READ | STGM_SHARE_EXCLUSIVE, 0, &pStream); if (FAILED(hr)) return hr; ComPtr<IMoniker> moniker; OleLoadFromStream(pStream, IID_IMoniker, (void**)&moniker); IBindCtx* pbc; CreateBindCtx(0, &pbc); ComPtr<IPolyline> polyline; hr = moniker->BindToObject(pbc, NULL, IID_IPolyline, (void**)&polyline); if (FAILED(hr)) { return -1; } ComPtr<IPolyline> polyline2; hr = moniker->BindToObject(pbc, NULL, IID_IPolyline, (void**)&polyline2); if (FAILED(hr)) { return -1; } outputPoints(polyline); outputPoints(polyline2); polyline->put_Color(RGB(0xff, 0x00, 0x00)); COLORREF value; polyline->get_Color(&value); assert(value == RGB(0xff, 0x00, 0x00)); return 0; }
int PolylineTest::readPersistFile() { ComPtr<IPolyline> pl; ComPtr<IPersistFile> pf; auto hr = CoCreateInstance(CLSID_PolylineObj, NULL, CLSCTX_INPROC_SERVER, IID_IPolyline, (void**)&pl); if (FAILED(hr)) { return -1; } pl->QueryInterface(IID_IPersistFile, (void**)&pf); hr = pf->Load(kFileName, STGM_READ | STGM_SHARE_EXCLUSIVE); if (FAILED(hr)) { TRACE("load persist file failed\n"); return -1; } outputPoints(pl); return 0; }
int PolylineTest::writePersistFile() { ComPtr<IPolyline> pl; auto hr = CoCreateInstance(CLSID_PolylineObj, NULL, CLSCTX_INPROC_SERVER, IID_IPolyline, (void**)&pl); if (FAILED(hr)) { return -1; } LPTYPEINFO pTypeInfo = NULL; LPTYPELIB pTypelib = NULL; IRecordInfo* pRecInfo = NULL; hr = LoadRegTypeLib(LIBID_GraphicsLibrary, 1, 0, GetUserDefaultLCID(), &pTypelib); _ASSERT(SUCCEEDED(hr) && pTypelib); hr = pTypelib->GetTypeInfoOfGuid(__uuidof(PolyPoint), &pTypeInfo); _ASSERT(SUCCEEDED(hr) && pTypeInfo); hr = GetRecordInfoFromTypeInfo(pTypeInfo, &pRecInfo); _ASSERT(SUCCEEDED(hr) && pRecInfo); pTypeInfo->Release(); pTypelib->Release(); std::vector<POINT> points = { { 1, 2 }, { 100, 200 }, { 300, 400 } }; auto psa = SafeArrayCreateVectorEx(VT_RECORD, 0, points.size(), pRecInfo); PolyPoint* pps; SafeArrayAccessData(psa, (void**)&pps); _ASSERT(psa); for (size_t i = 0; i < points.size(); ++i) { pps[i].x = points[i].x; pps[i].y = points[i].y; } pl->put_Points(psa); outputPoints(pl); ComPtr<IPersistFile> pf; pl->QueryInterface(IID_IPersistFile, (void**)&pf); pf->Save(kFileName, TRUE); pf->SaveCompleted(kFileName); return 0; }
int main() { cout << "MLS Season predictor Written by Derek Gathright [email protected]\n"; srand ( time(NULL) ); int teamSkill[12], teamPoints[12], teamHomeAdvantage[12], tieRatio = 6, wins[12], ties[12], losses[12]; char game[12][12], realResults = 'y', gameDiv[12][12], repeat = 'y'; teamSkill[0] = 5;// LA teamSkill[1] = 7;// KC teamSkill[2] = 4;// SJ teamSkill[3] = 4;// Colorado teamSkill[4] = 7;// Chicago teamSkill[5] = 5;// Dallas teamSkill[6] = 7;// Tampa Bay teamSkill[7] = 4;// Columbus teamSkill[8] = 6;// DC teamSkill[9] = 6;// NY teamSkill[10] = 4;// Miami teamSkill[11] = 3;// NE teamHomeAdvantage[0] = 2;// LA teamHomeAdvantage[1] = 1;// KC teamHomeAdvantage[2] = 3;// SJ teamHomeAdvantage[3] = 2;// Colorado teamHomeAdvantage[4] = 2;// Chicago teamHomeAdvantage[5] = 2;// Dallas teamHomeAdvantage[6] = 1;// Tampa Bay teamHomeAdvantage[7] = 2;// Columbus teamHomeAdvantage[8] = 3;// DC teamHomeAdvantage[9] = 1;// NY teamHomeAdvantage[10] = 1;// Miami teamHomeAdvantage[11] = 1;// NE do { for (int i = 0; i <= 11; i++) teamPoints[i] = 0; //cout << "Would you like to use the real results from the MLS games so far? (y/n): "; //cin >> realResults; for (int count = 0; count < 1; count++) for (int i = 0; i <= 11; i++) for (int j = 0; j <= 11; j++) { wins[i] = 0; ties[i] = 0; losses[i] = 0; game[i][j] = ' '; if(i != j) game[i][j] = getResult(teamSkill[i], teamHomeAdvantage[j], teamSkill[j], tieRatio); gameDiv[i][j] = ' '; if(i != j) gameDiv[i][j] = getResult(teamSkill[i], teamHomeAdvantage[j], teamSkill[j], tieRatio); } if ((realResults == 'y') || (realResults == 'Y')) { // *** Input real results here *** // game[home][away] = 'home team result' // Ex. LA @ KC, KC wins // game[1][0] = 'W'; // game[1][0] = 'F'; /* LA KC SJ Col Chi Dal TB CB DC NY Mia NE LA - .-. .-. .-x . . . . . . . . KC .-x - .-. .-. . . . . . . x . SJ .-x .-. - .-. . x . . . . . . Col .-. .-. .-. - . . . . . x x . Chi . . . . - .-. .-. .-. x . . . Dal . . . . .-x - .-. .-. . . . . TB . . . . .-. .-x - .-x . . . . C-Bus . x . . .-x .-. .-. - . . . . DC . x . . . . . . - .-. .-. .-x NY . . . . . . x . .-. - .-. .-x Mia . x x . . . . . .-. .-. - .-. NE . . . . . . . . .-. .-. .-x - */ // 4/7 games gameDiv[2][0] = 'W'; // LA @ SJ gameDiv[9][11] = 'W'; // NE @ NY game[8][1] = 'W'; // KC @ DC game[10][3] = 'W'; // Col @ Mia gameDiv[7][4] = 'T'; // Chi @ Clb gameDiv[5][6] = 'L'; // TB @ Dal // 4/14 games game[2][5] = 'L'; // Dal @ SJ gameDiv[6][7] = 'L'; // Clb @ TB gameDiv[11][10] = 'L'; // Mia @ NE gameDiv[1][0] = 'W'; // LA @ KC game[3][9] = 'T'; // NY @ Col game[4][8] = 'W'; // DC @ Chi // 4/18 games game[10][1] = 'W'; // Mia @ KC // 4/21 games gameDiv[0][3] = 'W'; //Colorado at Los Angeles game[9][6] = 'L'; //Tampa Bay at MetroStars gameDiv[5][4] = 'W'; //Chicago at Dallas game[10][2] = 'W'; //San Jose at Miami game[7][1] = 'L'; //Kansas City at Columbus gameDiv[8][11] = 'W'; //New England at D.C. United } for (int i = 0; i < 12; i++) { if (i < 4) for (int k = 4; k < 12; k++) gameDiv[i][k] = ' '; if ((i > 3) && (i < 8)) for (int k = 0; k < 12; k++) if ((k < 4) || (k > 7)) gameDiv[i][k] = ' '; if (i > 7) for (int k = 0; k < 8; k++) gameDiv[i][k] = ' '; } for (int home = 0; home <= 11; home++) for (int away = 0; away <= 11; away++) { if (game[home][away] == 'W'){ teamPoints[home] = teamPoints[home] + 3; wins[home] = wins[home] + 1; losses[away] = losses[away] + 1; } if (game[home][away] == 'T'){ teamPoints[home] = teamPoints[home] + 1; ties[home] = ties[home] + 1; } if (game[home][away] == 'L'){ teamPoints[away] = teamPoints[away] + 3; wins[away] = wins[away] + 1; losses[home] = losses[home] + 1; } if (game[home][away] == 'T'){ teamPoints[away] = teamPoints[away] + 1; ties[away] = ties[away] + 1; } if (gameDiv[home][away] == 'W'){ teamPoints[home] = teamPoints[home] + 3; wins[home] = wins[home] + 1; losses[away] = losses[away] + 1; } if (gameDiv[home][away] == 'T'){ teamPoints[home] = teamPoints[home] + 1; ties[home] = ties[home] + 1; } if (gameDiv[home][away] == 'L'){ teamPoints[away] = teamPoints[away] + 3; wins[away] = wins[away] + 1; losses[home] = losses[home] + 1; } if (gameDiv[home][away] == 'T'){ teamPoints[away] = teamPoints[away] + 1; ties[away] = ties[away] + 1; } } outputPoints(teamPoints, wins, ties, losses); outputTable(game, gameDiv); //cout << "\n\tNote: All results are the home teams results. Read the HOME teams on the" << "left and the AWAY teams on top."; //----------------------------------------------- int place[11], team[11], temp; for (int i = 0; i < 12; i++) { place[i] = teamPoints[i]; team[i] = i; } for (int i = 11; i>=0; i--) { for (int j = 0; j<i; j++) { if (teamPoints[j] > teamPoints[j+1]) { temp = teamPoints[j]; teamPoints[j] = teamPoints[j+1]; teamPoints[j+1] = temp; temp = team[j]; team[j] = team[j+1]; team[j+1] = temp; } } cout << endl; if (i ==11) cout << endl; if (team[i] == 1) cout << "KC "; else if (team[i] == 2) cout << "SJ "; else if (team[i] == 3) cout << "Col "; else if (team[i] == 4) cout << "Chi "; else if (team[i] == 5) cout << "Dal "; else if (team[i] == 6) cout << "TB "; else if (team[i] == 7) cout << "C-Bus"; else if (team[i] == 8) cout << "DC "; else if (team[i] == 9) cout << "NY "; else if (team[i] == 10) cout << "Mia "; else if (team[i] == 11) cout << "NE "; else cout << "LA "; cout << " - " << teamPoints[i]; if (i == 4) cout << "\n----------"; } //----------------------------------------------- cout << "\n\nWould you like to run the program again? (y/n): "; cin >> repeat; if ((repeat == 'y') || (repeat == 'Y')) cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"; } while ((repeat == 'y') || (repeat == 'Y')); cout << "\nType something to exit: "; char a; cin >> a; }