Results 1 to 5 of 5

Thread: GUI

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date: Jul:2008
    Location: Rousse
    Posts: 20

    GUI

    ! , " ". , , , , ++ (C# , ). , 3 4 , "" , . , . GUI( ), . Visual Studio 2010.

    :
    , :
    * ;
    * ;
    * ;
    * ;
    *
    ,

    Code:
    // mnp.h
    
    #include <conio.h>
    #include <windows.h>
    #include <iostream>
    #include <fstream>
    #include <string>
    #include <vector>
    #include <set>
    
    using namespace std;
    
    vector < vector < int > > vectInput;			// input functions
    vector < vector < int > > vectOutputs;		// output functions
    vector < vector < int > > vectIterations;	// Predstavqne na mrejata kato posledovatelnost ot markirovki,
    										//masiva e s razmernost 10 i pazi pyrvite 10 iteracii na mrejata
    
    vector < vector < int > > vectReachability;	// pazi mnojestvoto na dostijimost, vseki element na vektora e
    										// masiv ot celo4isleni stoinosti, vsqka stoinost predstavlqva
    										// broq na markirovkite v dadena poziciq
    
    vector < int > vectReachabilityPass;		// pokazva pri koi prehod e stanalo srabotvaneto, kogato se tyrsi
    										// mnojestvoto na dostijimost, za da moje da se izpolzwa po kysno
    										// pri zapisa vyv faila
    vector < int > vectMarkers;				// pazi markerite, masiva e s razmernost broq na poziciite
    
    void ChangeMarkers();					// Smenq markerite, ako potrebitelq izbere tova
    void StartIteration();					// Zapo4va tyrsene na pyrvite deset slu4aini iteracii na mrejata
    void FindAllPossibleSteps();			// namira mnojestvoto na dostijimost
    void SaveToFile();						// zapisva mnojestvoto v tekstov fail
    void ChangeColor(char* pchColor);		// smenq cveta na konzolata
    void main();
    
    // Promenlivi i funkcii preobrazuva6ti i risuva6ti mrejata v dyrvo
    vector <int> vectNodeLevelChildCount;	//help drawing tree
    vector < vector <int> > vectNodes;	// keep all nodes, and their subnodes
    void ConvertToTree();
    void DrawTree(int iCurNode, int iNodeLevel);
    Code:
    // mnp.cpp
    
    #include "mnp.h"
    
    void main()
    {
    	ifstream f("input.txt");
    
    	string strBuffer;	// working buffer
    	f>>strBuffer;	// skip one line
    	
    	// read input functions
    	//--------------------------------------
    	f>>strBuffer;
    	do
    	{
    		vectInput.push_back(vector<int>()); // dobavq nov element v kraq na vektora, sled posledniq
    		
    		int iEqual = strBuffer.find("="); // V tekstoviq fail se tyrsi "="
    		strBuffer = strBuffer.substr( iEqual+2, strBuffer.size() - (iEqual+3) ); // Vzema se samo nomera na prehoda
    
    		char* token = strtok( (char*)strBuffer.c_str(), "," );
    		// Note: strtok is deprecated; consider using strtok_s instead
    		while( token != NULL )
    		{
    			// While there are tokens in "string"
    			string strToken = string(token);
    			strToken = strToken.substr(1,string(token).size()-1);
    			int iPoint = atoi((char*)strToken.c_str());
    			vectInput[vectInput.size()-1].push_back(iPoint);
    
    			// Get next token: 
    			token = strtok( NULL, "," );
    		}
    
    		f>>strBuffer;
    	}
    	while(strBuffer!="//");
    
    	f>>strBuffer;	// skip one line
    	
    	// read input functions
    	//--------------------------------------
    	f>>strBuffer;
    	do
    	{
    		vectOutputs.push_back(vector<int>());
    		
    		int iEqual = strBuffer.find("=");
    		strBuffer = strBuffer.substr( iEqual+2, strBuffer.size() - (iEqual+3) );
    
    		char* token = strtok( (char*)strBuffer.c_str(), "," );
    		// Note: strtok is deprecated; consider using strtok_s instead
    		while( token != NULL )
    		{
    			// While there are tokens in "string"
    			string strToken = string(token);
    			strToken = strToken.substr(1,string(token).size()-1);
    			int iPoint = atoi((char*)strToken.c_str());
    			vectOutputs[vectOutputs.size()-1].push_back(iPoint);
    
    			// Get next token: 
    			token = strtok( NULL, "," );
    		}
    
    		f>>strBuffer;
    	}
    	while(strBuffer!="//");
    	//--------------------------------------
    	// read input functions
    
    	f>>strBuffer;	// skip one line
    
    	// Read Markers
    	//--------------------------------------
    	f>>strBuffer;
    	//vectMarker.push_back(vector<int>());
    		
    	int iEqual = strBuffer.find("=");
    	strBuffer = strBuffer.substr( iEqual+2, strBuffer.size() - (iEqual+3) );
    
    	char* token = strtok( (char*)strBuffer.c_str(), "," );
    	// Note: strtok is deprecated; consider using strtok_s instead
    	while( token != NULL )
    	{
    		// While there are tokens in "string"
    		string strToken = string(token);
    		int iPoint = atoi((char*)strToken.c_str());
    		vectMarkers.push_back(iPoint);
    
    		// Get next token: 
    		token = strtok( NULL, "," );
    	}
    	//--------------------------------------
    	// Read Markers
    
    	// clear screen
    	system("cls");
    	ChangeColor("green");
    	cout<<"Mrejata e pro4etena ot faila.\r\nTekushtata markirovka e: Mo = {";
    	for(int i=0; i<vectMarkers.size() ; i++)
    		if(i<vectMarkers.size()-1)
    			cout<<vectMarkers[i]<<",";
    		else
    			cout<<vectMarkers[i]<<"}\r\n";
    
    
    	// Preobrazuvane na mrejata vyv dyrvo, narisuvane na dyrvoto
    	ConvertToTree();
    	ChangeColor("white");
    	cout<<"\r\n\r\n\r\nPredstavqne na mejata kato dyrvo\r\n1\r\n";
    	DrawTree(0,0);
    
    
    
    	cout<<"\r\nIskate li da smenite markirovkata Y/N? ";
    	char chChoise=getch();
    	putch(chChoise);
    
    	if(chChoise=='y' || chChoise=='Y')
    	{
    		ChangeMarkers();
    	}
    	
    	StartIteration();
    	
    	ChangeColor("magenta");
    
    	// Output first 10 iterations
    	cout<<"\r\n\r\nPredstavqne na mrejata kato posledovatelnost ot markirovki.\r\nPokazani sa samo pyrvite 10 iteracii, za6oto iteraciite biha mogli da prodyljat do bezkrai.\r\n";
    	for(int t=0 ; t<vectIterations.size() ; t++)
    	{
    		cout<<"\r\nM"<<t<<" = {";
    		for(int j=0 ; j<vectIterations[t].size() ; j++)
    			if(j==vectIterations[t].size()-1)
    				cout<<vectIterations[t][j];
    			else
    				cout<<vectIterations[t][j]<<",";
    
    		cout<<"}";
    	}
    	if(vectIterations.size()<10)
    		cout<<"\r\nNqma pove4e razre6eni prehodi.";
    
    	ChangeColor("red");
    	FindAllPossibleSteps();
    
    	SaveToFile();
    
    	getch();
    
    	f.close();
    
    }
    
    void ChangeMarkers()
    {
    	ChangeColor("yelow");
    
    	cout<<"\r\n\r\nMolq razdelqite poziciite sys zapetaiki, sled kato vyvedete vsi4ki pozicii natisnete enter";
    	cout<<"\r\n\r\nMo = {";
    	string strBuffer;
    	while(1)
    	{
    		char ch = getch();
    		
    		if(ch==13)
    			break;
    
    		if(ch==8)
    		{
    			putch(8);
    			putch(' ');
    			putch(8);
    			strBuffer.erase(strBuffer.end()-1);
    			continue;
    		}
    
    		putch(ch);
    		
    		strBuffer += ch;
    	}
    
    	// Read Markers from string
    	//--------------------------------------
    	vectMarkers.clear();
    	
    	char* token = strtok( (char*)strBuffer.c_str(), "," );
    	// Note: strtok is deprecated; consider using strtok_s instead
    	while( token != NULL )
    	{
    		// While there are tokens in "string"
    		string strToken = string(token);
    		int iPoint = atoi((char*)strToken.c_str());
    		vectMarkers.push_back(iPoint);
    
    		// Get next token: 
    		token = strtok( NULL, "," );
    	}
    	//--------------------------------------
    	// Read Markers
    
    	if(vectMarkers.size()==vectInput.size())
    		cout<<"}\r\n\r\n"<<"Promqnata na markerite zavyrshi uspeshno.  ";
    	else
    		cout<<"}\r\n\r\n"<<"Greshka pri vyvejdaneto na markerite.  ";
    }
    
    void StartIteration()
    {
    	if(vectIterations.size()>=10)
    		return;
    
    	if(vectIterations.empty())
    		vectIterations.push_back(vectMarkers);
    
    	vector <int> vectPoints(vectIterations[vectIterations.size()-1]);
    
    	for(int i=0 ; i<vectInput.size() ; i++ )
    	{
    		bool bAllMatch=true;
    		for( int j = 0 ; j<vectInput[i].size() ; j++ )
    		{
    			if(vectPoints[vectInput[i][j]-1]==0)
    			{
    				bAllMatch=false;
    				break;
    			}
    		}
    
    		if(bAllMatch)
    		{
    			for(int k=0; k<vectInput[i].size(); k++)
    				vectPoints[vectInput[i][k]-1]--;
    				
    			for(int n=0; n<vectOutputs[i].size() ; n++)
    				vectPoints[vectOutputs[i][n]-1]++;
    
    			vectIterations.push_back(vectPoints);
    
    			StartIteration();
    						
    			break;
    		}		
    	}
    }
    
    void FindAllPossibleSteps()
    {
    	cout<<"\r\n\r\nNamirane na mnogjestvoto na dostijimost na tekushtata markirovka.\r\n";
    
    	int iCount=0;
    	for(int i=0 ; i<vectInput.size() ; i++ )
    	{
    		vector <int> vectPoints(vectMarkers);
    
    		bool bAllMatch=true;
    		for( int j = 0 ; j<vectInput[i].size() ; j++ )
    		{
    			if(vectPoints[vectInput[i][j]-1]==0)
    			{
    				bAllMatch=false;
    				break;
    			}
    		}
    
    		if(bAllMatch)
    		{
    			for(int k=0; k<vectInput[i].size(); k++)
    				vectPoints[vectInput[i][k]-1]--;
    				
    			for(int n=0; n<vectOutputs[i].size() ; n++)
    				vectPoints[vectOutputs[i][n]-1]++;
    			
    			vectReachability.push_back(vectPoints);
    			vectReachabilityPass.push_back(i+1);
    		}		
    	}
    
    	for(int t=0 ; t<vectReachability.size() ; t++)
    	{
    		cout<<"Pri srabotvane na t"<<t+1<<" M"<<++iCount<<" = {";
    		for(int k=0 ; k<vectReachability[t].size() ; k++)
    			if(k==vectReachability[t].size()-1)
    				cout<<vectReachability[t][k]<<"}";	
    			else
    				cout<<vectReachability[t][k]<<",";
    
    		cout<<"\r\n";
    	}
    
    	if(vectReachability.empty())
    		cout<<"Nito edin ot prehodite ne moje da sraboti.";
    	else cout<<"\r\nFaila e zapisan uspeshno.";
    }
    
    void SaveToFile()
    {
    	vectReachability.insert(vectReachability.begin(),vectMarkers);
    
    	ofstream f("input.txt",ios_base::out|ios_base::app);
    
    	f<<"\r\n\r\nMnogjestvoto na dostijimost na tekushtata markirovka.\r\n";
    
    	for(int i=0 ; i<vectReachability.size() ; i++)
    	{
    		if(i==0)
    			f<<"Nachalno systoqnie   M"<<i<<" = {";
    		else
    			f<<"Pri srabotvane na t"<<vectReachabilityPass[i-1]<<" M"<<i<<" = {";
    
    		for(int k=0 ; k<vectReachability[i].size() ; k++)
    			if(k==vectReachability[i].size()-1)
    				f<<vectReachability[i][k]<<"}";	
    			else
    				f<<vectReachability[i][k]<<",";
    
    		f<<"\r\n";
    	}
    
    	if(vectReachability.empty())
    		f<<"Nito edin ot prehodite ne moje da sraboti.";
    
    	f.close();
    }
    
    void ChangeColor(char* pchColor)
    {
    	HANDLE hCon = GetStdHandle(STD_OUTPUT_HANDLE);
    
    	if((*pchColor)==*(char*)"white")
    	{
    		SetConsoleTextAttribute(hCon, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY );
    	}
    	if((*pchColor)==*(char*)"red")
    	{
    		SetConsoleTextAttribute(hCon, FOREGROUND_RED | FOREGROUND_INTENSITY );
    	}
    	if((*pchColor)==*(char*)"green")
    	{		
    		SetConsoleTextAttribute(hCon, FOREGROUND_GREEN | FOREGROUND_INTENSITY );
    	}
    	if((*pchColor)==*(char*)"yelow")
    	{
    		SetConsoleTextAttribute(hCon, FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY );
    	}
    	if((*pchColor)==*(char*)"magenta")
    	{
    		SetConsoleTextAttribute(hCon, FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY );
    	}
    }
    
    void ConvertToTree()
    {
    	set <int> mySet;	// read all points, p1,p2,p3... and save them with no repetitions
    
    	for(int h=0; h<vectInput.size() ; h++)
    		for(int j=0; j<vectInput[h].size() ; j++)
    			mySet.insert(vectInput[h][j]);
    
    	for(int ii=0; ii<vectOutputs.size() ; ii++)
    		for(int j=0; j<vectOutputs[ii].size() ; j++)
    			mySet.insert(vectOutputs[ii][j]);
    
    	// count nodes
    	vectNodes.resize(mySet.size());//vectInput.size());
    
    	for(int i=0 ; i<vectInput.size() ; i++ )
    	{
    		for(int j=0;j<vectInput[i].size();j++)
    		{
    			//vectNodes.push_back(vector<int>());
    
    			for(int p=0 ;p<vectOutputs[i].size() ; p++)
    			{
    				if( vectOutputs[i][p]==1 )
    					continue;
    
    				bool bFinded=false;
    				for(int k=0;k<vectNodes.size() ; k++)
    					for(int t=0 ; t<vectNodes[k].size() ;t++)
    						if(vectOutputs[i][p]==vectNodes[k][t])
    							bFinded=true;
    										
    				if(bFinded)
    					continue;
    
    				vectNodes[vectInput[i][j]-1].push_back(vectOutputs[i][p]);
    			}
    		}
    		
    	}
    }
    
    void DrawTree(int iCurNode, int iNodeLevel)
    {
    	if(iCurNode+1>vectNodeLevelChildCount.size())
    		vectNodeLevelChildCount.push_back(vectNodes[iCurNode].size());
    	else
    		vectNodeLevelChildCount[iCurNode]=vectNodes[iCurNode].size();
    
    	for(size_t i=0 ; i<vectNodes[iCurNode].size() ; i++)
    	{
    		for(size_t j=0 ; j<iNodeLevel; j++)
    			if(vectNodeLevelChildCount[j]>0)
    				cout<<(char)179<<" ";
    			else
    				cout<<"  ";
    
    		if(vectNodeLevelChildCount[iNodeLevel]==1)
    			cout<<(char)192<<"-";
    		else
    			cout<<(char)195<<"-";	// 195 +
    		
    		cout<<vectNodes[iCurNode][i];
    		cout<<"\r\n";
    
    		
    		vectNodeLevelChildCount[iNodeLevel]--;
    		
    		DrawTree(vectNodes[iCurNode][i]-1,iNodeLevel+1);
    
    		if(vectNodeLevelChildCount[vectNodeLevelChildCount.size()-1]==0)
    			vectNodeLevelChildCount.pop_back();
    	}
    }
    :
    Code:
    //_pro4itane_na_vhodnite_funkcii
    I(t1)={p2}
    I(t2)={p1}
    I(t3)={p2}
    I(t4)={p4}
    I(t5)={p3,p5}
    // pro4itane_na_izhodnite_funkcii
    O(t1)={p1}
    O(t2)={p3,p5}
    O(t3)={p3}
    O(t4)={p2}
    O(t5)={p4}
    // pro4itane_na_markirovkata
    Mo={1,0,0,1,0}

    *.exe :

    input.txt
    mnp.exe


    , !

  2. #2
    ! vbTheKing's Avatar
    Join Date: Sep:2003
    Location:
    Posts: 4,138
    , GUI ? - , , . 3-/4- , ? - ?
    ''? * *
    - !
    ...

  3. #3
    1+1=11 svr's Avatar
    Join Date: Sep:2006
    Location: Inferno, Act 1
    Posts: 790
    wxWidgets QT - GUI- ++. view , . - update, . QT wxWidgets - , , .
    MSI B450 Gaming Pro Carbon AC | Ryzen 9 5900x | HyperX Predator 3200 | Asus Strix 3090 | Kingston KC3000 2TB | WD Red 4TB | Dell G3223Q + LG 27UK650-W | Arctic Freezer 360 | Seasonic Focus GX-1000 | Lian Li O11 Dynamic

  4. #4
    ɐ-əpoɔᴉu⋂ ɐ ə anrieff's Avatar
    Join Date: Apr:2004
    Location: Sofia
    Posts: 8,448
    wxWidgets Qt, ,
    , . .
    "640K ught to be enough for anybody" - Bill Gates, 1981
    ::Machine specs::Fract::AGG::::Baileys::blog::YouTube channel

  5. #5
    Registered User
    Join Date: Jul:2008
    Location: Rousse
    Posts: 20
    Qt .

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Copyright © 1999-2011 . .
iskamPC.com | mobility.BG | Bloody's Techblog | | 3D Vision Blog |