Code:
#include "tt.h"
#include <process.h>
using namespace std;
void clrscr();
void Func1(void *);
void Func2(void *);
CRITICAL_SECTION Section;
int main()
{
HANDLE hThreads[2];
InitializeCriticalSection(&Section);
hThreads[0] = (HANDLE)_beginthread(Func1,0,NULL);
hThreads[1] = (HANDLE)_beginthread(Func2,0,NULL);
WaitForMultipleObjects(2,hThreads,TRUE,INFINITE);
DeleteCriticalSection(&Section);
cout << "Main exit" << endl;
}
void clrscr()
{
COORD coordScreen = { 0, 0 };
DWORD cCharsWritten;
CONSOLE_SCREEN_BUFFER_INFO csbi;
DWORD dwConSize;
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleScreenBufferInfo(hConsole, &csbi);
dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
FillConsoleOutputCharacter(hConsole, TEXT(' '), dwConSize, coordScreen, &cCharsWritten);
GetConsoleScreenBufferInfo(hConsole, &csbi);
FillConsoleOutputAttribute(hConsole, csbi.wAttributes, dwConSize, coordScreen, &cCharsWritten);
SetConsoleCursorPosition(hConsole, coordScreen);
}
void Func1(void *P)
{
void clrscr();
EnterCriticalSection(&Section);
time_t rawtime;
struct tm * timeinfo;
time ( &rawtime );
timeinfo = localtime ( &rawtime );
printf ("Current date and time is: %s", asctime (timeinfo));
Sleep(1000);
clrscr();
LeaveCriticalSection(&Section);
}
void Func2(void *P)
{
//---ints and vars----------------
double num3; //--
double equal1; //--
double equal2; //--
int input; //--
long c; //--
float equal; //--
float a; //--
float b; //--
float d; //--
float e; //--
float f; //--
float per1; //--
float per2; //--
string name; //--
string info; //--
string my_string2 = ".txt"; //--
string my_string3; //--
string pick; //--
string no; //--
string yes; //--
//--------------------------------
EnterCriticalSection(&Section);
bool pQuit = false;
while( false == pQuit )
{
//--------menu---------------------------
cout<<"0. Exit\n"; //--
cout<<"1. Add\n"; //--
cout<<"2. Subtract\n"; //--
cout<<"3. Multiply\n"; //--
cout<<"4. Divide\n"; //--
cout<<"5. Absolute Value\n"; //--
cout<<"6. Percent of\n"; //--
cout<<"7. Linear Euations Slops\n";//--
cout<<"8. Polygons\n"; //--
cout<<"9. Open File\n"; //--
cout<<"10. Save File\n"; //--
cout<<"11. Size of File\n"; //--
cout<<"Selection: "; //--
//---------------------------------------
//----------code---------->
cin>> input;
switch ( input ) {
case 0: //Exit
pQuit = true;
break;
case 1: //Add
cout << "Enter two numbers to add: "<<endl;
cout << ">";
cin >> a;
cout << ">";
cin >> b;
equal = a+b;
cout << "answer = "<<equal<<endl;
system("pause");
clrscr();
break;
case 2: //Subtract
cout << "Enter two numbers to subtract: "<<endl;
cout << ">";
cin >> a;
cout << ">";
cin >> b;
equal = a-b;
cout << "answer = " <<equal<<endl;
system("pause");
clrscr();
break;
case 3: //Multiply
cout << "Enter two numbers to multiply: "<<endl;
cout << ">";
cin >> a;
cout << ">";
cin >> b;
equal = a*b;
cout << "answer = " <<equal<<endl;
system("pause");
clrscr();
break;
case 4: //Divide
cout << "Enter two numbers to divide: "<<endl;
cout << ">";
cin >> a;
cout << ">";
cin >> b;
equal = a/b;
cout << "answer = " <<equal<<endl;
system("pause");
clrscr();
break;
case 5: //Absolute value
cout << "Enter a number to find its absolute value: "<<endl;
cout << ">";
cin >> c;
equal = abs(c);
cout << "answer = " <<equal<<endl;
system("pause");
clrscr();
break;
case 6: //Percent of
cout << "Enter two numbers (ex. 25 of 75 = 33.33%) "<<endl;
cout << ">";
cin >> per1;
cout << ">";
cin >> per2;
equal2 = (per1 / per2) * 100;
cout << "answer = " << equal2 << "%"<<endl;
system("pause");
clrscr();
break;
case 7: //Linear Equations Slops
cout << "What is the y m x (ex. (2,5) m=1 so y=1 m=5 x=2) "<<endl;
cout << ">";
cin >> a;
cout << ">";
cin >> b;
cout << ">";
cin >> d;
equal=b*d;
f=equal-a;
cout << "answer is y="<<a<<"x="<<f<<endl;
system("pause");
clrscr();
break;
case 8: //Polygon
cout << "Enter a polygon number: "<<endl;
cout << ">";
cin >> a;
if(a == 1)
cout<< "Does not exist"<<endl;
else if(a == 2)
cout<< "Does not exist"<<endl;
else if(a == 3)
cout<< "Tigon"<<endl;
else if(a == 4)
cout<< "Tetragon"<<endl;
else if(a == 5)
cout<< "Pentagon"<<endl;
else if(a == 6)
cout<< "Hexagon"<<endl;
else if(a == 7)
cout<< "Heptagon" <<endl;
else if(a == 8)
cout<< "Octagon"<<endl;
else if(a == 9)
cout<< "Enneagon"<<endl;
else if(a == 10)
cout<< "Decagon"<<endl;
else if(a == 11)
cout<< "Hendecagon"<<endl;
else if(a == 12)
cout<< "Dodecagon"<<endl;
else if(a == 13)
cout<< "Triskaidecagon"<<endl;
else
cout << "I'm sorry thats not in my database."<<endl;
system("pause");
clrscr();
break;
case 9:
{
string line;
cout<<"What is the name of the file? ";
getchar();
getline(cin, name);
my_string3 = name;
ifstream myfile (my_string3.c_str());
if (myfile.is_open())
{
while (! myfile.eof() )
{
getline (myfile,line);
cout << line << endl;
}
myfile.close();
}
else cout << "Unable to open file";
getchar();
clrscr();
break;
}
case 10:
{
cout<<"What is the name of the file? ";
getchar();
getline(cin, name);
ofstream myfile;
my_string3 = name+my_string2;
myfile.open (my_string3.c_str());
cout<<"Please enter what to save: ";
getline(cin,info);
myfile << info;
myfile.close();
clrscr();
break;
}
case 11:
{
long begin,end;
cout<<"What is the name of the file? ";
getchar();
getline(cin, name);
my_string3 = name;
ifstream myfile (my_string3.c_str());
begin = myfile.tellg();
myfile.seekg (0, ios::end);
end = myfile.tellg();
myfile.close();
cout << "size is: " << (end-begin) << " bytes."<<endl;
getchar();
clrscr();
break;
}
default:
cout<<"Error, bad input, quitting\n";
clrscr();
break;
}
cin.get();
}
LeaveCriticalSection(&Section);
}
Its perty long>< But I want it to post the time and refrush the time everyone 1 sec as the loop waits for input from user. I can make the time refrush it self by puting a another loop but then that will efftect the other one b/c it wont go to the main loop.