Your Code Here...

pes.h>#include <math.h> #include <string.h>
unsigned long StrToInt(std::string str){
unsigned long rint = NULL;
unsigned long size = str.size();
unsigned long fi[sizeof(str)];
unsigned long mul;
for( int i = 0; i != size; i++){
if( str.at(i) == '0' ) fi[i] = 0;
if( str.at(i) == '1' ) fi[i] = 1;
if( str.at(i) == '2' ) fi[i] = 2;
if( str.at(i) == '3' ) fi[i] = 3;
if( str.at(i) == '4' ) fi[i] = 4;
if( str.at(i) == '5' ) fi[i] = 5;
if( str.at(i) == '6' ) fi[i] = 6;
if( str.at(i) == '7' ) fi[i] = 7;
if( str.at(i) == '8' ) fi[i] = 8;
if( str.at(i) == '9' ) fi[i] = 9;
}
for(int i = 0; i != str.size() ; i++){
mul = (1 * pow(10, (double)size-1));
size--;
rint += ( mul * fi[i]);
}
return rint;
}
int i = (int) StrToInt("5192491");
Your code to convert alpha to numeric is a little larger than it needs to be..Atoi isn't always a reliable routine to use so a smaller alternative could be to use #include "stdafx.h"
#include "windows.h"
#include <iostream>
#include <cmath>
using namespace std;
struct Define
{
int option;
char operators;
long basica;
long basicb;
float adva;
long answerbasic;
float answeradv;
};
Define df;
namespace Calculator
{
int MainLobby( )
{
printf( " \nWelcome to Calculator(ASCII)!\n");
printf( " Enter: ");
printf( " '1' for Basic. ");
printf( " '2' for Advanced : ");
cin >> df.option;
return 0;
}
int BasicLobby( )
{
cout << " Enter operator ( +, -, *, / ): ";
cin >> df.operators;
cout << " Enter a number: ";
cin >> df.basica;
cout << " Enter another number: ";
cin >> df.basicb;
if ( df.operators == ('+') )
{
df.answerbasic = df.basica + df.basicb;
cout << df.basica << " " << df.operators << " " << df.basicb << " = " << df.answerbasic;
}
if ( df.operators == ('-') )
{
df.answerbasic = df.basica - df.basicb;
cout << df.basica << " " << df.operators << " " << df.basicb << " = " << df.answerbasic;
}
if ( df.operators == ('*') )
{
df.answerbasic = df.basica * df.basicb;
cout << df.basica << " " << df.operators << " " << df.basicb << " = " << df.answerbasic;
}
if ( df.operators == ('/') )
{
df.answerbasic = df.basica / df.basicb;
cout << df.basica << " " << df.operators << " " << df.basicb << " = " << df.answerbasic;
}
cout << "\n\n";
return 0;
}
int AdvancedLobby( )
{
cout << "Enter operators 's' for square root: ";
cin >> df.operators;
cout << "Enter a number: ";
cin >> df.adva;
if ( df.operators == ('s') )
{
df.answeradv = sqrt(df.adva);
cout << " square root " << df.adva << " = " << df.answeradv;
}
cout << "\n\n";
return 0;
}
}
int _tmain(int argc, _TCHAR* argv[])
{
while( 1 )
{
Restart:
Calculator::MainLobby( );
switch(df.option)
{
case (1): Calculator::BasicLobby( ); break;
case (2): Calculator::AdvancedLobby( ); break;
default: cout << "\nPlease enter 1 or 2."; break;
}
goto Restart;
}
return 0;
}
//GAKS.cpp written by master131
#include <Windows.h>
#include <iostream>
int main()
{
using namespace std;
char* keys[] = {"{LEFTMOUSE}", "{RIGHTMOUSE}", "{CANCEL}",
"{MIDDLEMOUSE}", "{XBUTTON1}", "{XBUTTON2}", "", "{BACKSPACE}", "{TAB}",
"","","{CLEAR}", "{ENTER}", "", "", "{SHIFT}", "{CTRL}", "{ALT}", "{PAUSE}", "{CAPSLOCK}" };
char* otherkeys[] = {"{SPACE}", "{PGUP}", "{PGDOWN}", "{END}", "{HOME}", "{LEFT ARROW}", "{UP ARROW}",
"{RIGHT ARROW}", "{DOWN ARROW}", "{SELECT}", "{PRINT}", "{EXECUTE}", "{PRNTSCREEN}", "{INS}",
"{DEL}", "{HELP}"};
char* standardkeys[] = {":", "+", ",", "-", ".", "/", "`"};
char* misckeys[] = {"[", "\\", "]", "'"};
char* numpadkeys[] = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "*", "+", "", "-", ".", "/"};
while(1)
{
for(int i = 0; i < 255; i++)
if(GetAsyncKeyState(i))
{
while(GetAsyncKeyState(i)) { };
if(i >= 1 && i <= 19) //Special Keys
cout << keys[i-1];
if(i >= 32 && i <= 47) //Other keys
cout << otherkeys[i-32];
if(i >= 48 && i <= 90) //Literal Keys
cout << (char)tolower(i);
if(i >= 96 && i <= 111) //Numpad keys
cout << numpadkeys[i-96];
if(i >= 112 && i <= 135) //F keys
cout << "{F" << i - 111 << "}";
if(i >= 186 && i <= 192) //Punctuation Keys
cout << standardkeys[i-186];
if(i >= 219 && i <= 222) //Misc keys
cout << misckeys[i-219];
}
Sleep(1);
}
return 0;
}
char pcName [MAX_COMPUTERNAME_LENGTH + 1]; DWORD dwPcName = sizeof ( pcName ); if ( GetComputerName (pcName,&dwPcName)) cFont->DrawText(300,300,Green,pcName,D3DFONT_SHADOW);
void Drawbatterylife( int x, int y )
{
SYSTEM_POWER_STATUS status;
GetSystemPowerStatus( &status );
int life = status.BatteryLifePercent;
char szLife[256];
sprintf(szLife,"%i",life);
DrawString(x, y, White, m_font, szLife);
switch (status.BatteryFlag) {
case 1:
DrawString( x, y + 17, White, m_font, "High");
break;
case 2:
DrawString( x, y + 17, White, m_font, "Low");
break;
case 4:
DrawString( x, y + 17, White, m_font, "Criticial");
break;
case 128:
DrawString( x, y + 17, White, m_font, "No system battery");
break;
case 256:
DrawString( x, y + 17, White, m_font, "Unknown status");
break;
}
}
// Calculating gas mileage
#include <iostream>
#include <iomanip>
using std::cin;
using std::cout;
using std::endl;
using std::setw;
using namespace std;
int main()
{
const int MAX(20); // Maximum number of values
double gas[ MAX ]; // Gas quantity in gallons
long miles[ MAX ]; // Odometer readings
int count(0); // Loop counter
char indicator('y'); // Input indicator
while( ('y' == indicator || 'Y' == indicator) && count < MAX )
{
cout << endl << "Enter gas quantity: ";
cin >> gas[count]; // Read gas quantity
cout << "Enter odometer reading: ";
cin >> miles[count]; // Read odometer value
++count;
cout << "Do you want to enter another(y or n)? ";
cin >> indicator;
}
if(count <= 1) // count = 1 after 1 entry completed
{ // ... we need at least 2
cout << endl << "Sorry - at least two readings are necessary.";
cin.get();
return 0;
}
// Output results from 2nd entry to last entry
for(int i = 1; i < count; i++)
{
cout << endl
<< setw(2) << i << "." // Output sequence number
<< "Gas purchased = " << gas[i] << " gallons" // Output gas
<< " resulted in " // Output miles per gallon
<< (miles[i] - miles[i - 1])/gas[i] << " miles per gallon.";
}
cout << endl;
system("PAUSE");
return 0;
}
#include <stdio.h>
#include <iostream>
#include <string>
#include <fstream>
#include <conio.h>
using namespace std;
void ReRun();
bool CopyF(char *SourceFile,char *DestinationFile);
void main()
{
system("cls");
cout << "Enter 'r' to read contents of an existing file." << endl;
cout << "Enter 'w' to write contents to a new file." << endl;
cout << "Enter 'a' to append contents of an existing file." << endl;
cout << "Enter 'c' to copy a file to another place." << endl;
cout << "Enter 'm' to move a file to another place." << endl;
cout << "Enter 'd' to delete an existing file." << endl << endl;
cout << "Enter your choice: ";
char choice;
cin >> choice;
switch(choice)
{
case 'r':
case 'R':
{
cin.ignore();
char FileName[FILENAME_MAX];
cout << endl << "Enter the directory appended by the filename you want to read data from: ";
cin.getline(FileName,FILENAME_MAX);
fstream ReadonlyFile;
ReadonlyFile.open(FileName,ios::in);
if(ReadonlyFile.is_open())
{
while(!ReadonlyFile.eof())
{
string CurrentLine;
cout << endl;
while(getline(ReadonlyFile,CurrentLine))
{
cout << CurrentLine << endl;
}
}
cout << endl << "Finished reading data from " << FileName << ".";
ReRun();
}
else
{
if(!ReadonlyFile)
{
cout << "File '" << FileName << "' does not exists.";
ReRun();
}
else
{
cout << "There is a problem reading file '" << FileName << "'.";
ReRun();
}
}
}
break;
case 'w':
case 'W':
{
cin.ignore();
char FileName[FILENAME_MAX];
cout << endl << "Enter the directory appended by the name of the new file you want to create: ";
cin.getline(FileName,FILENAME_MAX);
fstream WriteonlyFile;
WriteonlyFile.open(FileName,ios::out);
if(WriteonlyFile.is_open())
{
cout << endl << "Enter the data you want to enter to the file. Write '[Close]' on a new line to end writing to the file: " << endl << endl;
string NewData;
while( (getline(cin,NewData)))
{
if(NewData=="[Close]")
{
WriteonlyFile.close();
ReRun();
}
WriteonlyFile << NewData << endl;
}
WriteonlyFile.close();
}
else
{
cout << "Unable to create a new file '" << FileName << "'.";
ReRun();
}
}
break;
case 'a':
case 'A':
{
cin.ignore();
char FileName[FILENAME_MAX];
cout << endl << "Enter the directory appended by the name of the new file you want to append contents to: ";
cin.getline(FileName,FILENAME_MAX);
fstream AppendToFile;
AppendToFile.open(FileName,ios::out | ios::app);
if(AppendToFile.is_open())
{
cout << endl << "Enter the data you want to append to the file. Write '[Close]' on a new line to end writing to the file: " << endl << endl;
string NewData;
while( (getline(cin,NewData)))
{
if(NewData=="[Close]")
{
AppendToFile.close();
ReRun();
}
AppendToFile << endl << NewData;
}
AppendToFile.close();
}
else
{
cout << "Unable to open file '" << FileName << "' for appending.";
ReRun();
}
}
break;
case 'c':
case 'C':
{
cin.ignore();
char SourceFileName[FILENAME_MAX];
cout << endl << "Enter the directory appended by the name of the file you want to copy: ";
cin.getline(SourceFileName,FILENAME_MAX);
char DestinationFileName[FILENAME_MAX];
cout << endl << "Enter the directory appended by the name of the file you want the file to be copied: ";
cin.getline(DestinationFileName,FILENAME_MAX);
cout << endl << endl << "Copying " << SourceFileName << ". Please wait...";
if(CopyF(SourceFileName,DestinationFileName))
{
cout << endl << endl << "File " << SourceFileName << " successfully copied to " << DestinationFileName << ".";
}
ReRun();
}
break;
case 'm':
case 'M':
{
cin.ignore();
char SourceFileName[FILENAME_MAX];
cout << endl << "Enter the directory appended by the name of the file you want to move: ";
cin.getline(SourceFileName,FILENAME_MAX);
char DestinationFileName[FILENAME_MAX];
cout << endl << "Enter the directory appended by the name of the file you want the file to be moved: ";
cin.getline(DestinationFileName,FILENAME_MAX);
cout << endl << endl << "Moving " << SourceFileName << ". Please wait...";
if(CopyF(SourceFileName,DestinationFileName))
{
remove(SourceFileName);
cout << endl << endl << "File " << SourceFileName << " successfully moved to " << DestinationFileName << ".";
}
ReRun();
}
break;
case 'd':
case 'D':
{
cin.ignore();
char FileToDelete[FILENAME_MAX];
cout << endl << "Enter the directory appended by the name of the file you want to delete: ";
cin.getline(FileToDelete,FILENAME_MAX);
cout << "Deleting File: " << FileToDelete << ". Please wait...";
if(remove(FileToDelete))
{
cout << endl << endl << "File " << FileToDelete << " successfully deleted.";
}
ReRun();
}
break;
default:
{
cout << endl << "You have not entered a valid choice. " << endl << "Do you want to show the choices again ?";
cout << endl << endl << "Press 'y' if you want the choices to be showed again. Press any other key and press enter to exit the program:";
cout << endl ;
char choice;
cin >> choice;
if( choice =='y' || choice == 'Y')
main();
else
exit(0);
}
}
}
bool CopyF(char *SourceFileName,char *DestinationFileName)
{
fstream SourceFile;
fstream DestinationFile;
char *Buffer;
long SizeofFile;
SourceFile.open(SourceFileName,ios::in | ios::binary );
DestinationFile.open(DestinationFileName,ios::out | ios::binary );
SourceFile.seekg(0,ios::end);
SizeofFile = SourceFile.tellg();
SourceFile.seekg(0);
Buffer = new char[SizeofFile];
SourceFile.read(Buffer,SizeofFile);
DestinationFile.write(Buffer,SizeofFile);
delete[] Buffer;
DestinationFile.close();
SourceFile.close();
return true;
}
void ReRun()
{
cout << endl <<endl << "Do you wish to perform another operation ?" << endl;
cout << "Press 'y' to perform another operation or any other key to exit the program." << endl << endl;
cout << "Enter your choice: ";
char choice;
cin >> choice;
if(choice=='y' || choice == 'Y')
main();
else
exit(0);
}