Make a c++ game! Rules for playing the Name The State Game (single user option):
ID: 3578036 • Letter: M
Question
Make a c++ game!
Rules for playing the Name The State Game (single user option):
The program will read the information for one random state from the data file.
The program will provide an introductory message and ask the user if they want a summary of the rules.
The program will present the user with the 9 clues above in random order.
The program will keep score. A perfect score is 100. If the user correctly guesses the state after the first clue, their score is 100.
After each clue the user will be given an option of guessing the state or asking for another clue. The clues should be numbered (from 1 to 9) as they are presented so that the user knows how many clues they have used.
Each time the user makes an incorrect guess, 5 points will be deducted from their score.
Each time the user asks for another clue, 5 points will be deducted from their score.
Display the score after every clue or guess.
The game will end if their score drops to 0 without correctly guessing the state.
After the last clue the user should be given the option of guessing the state or giving up. If they give up, display the name of the state.
When the user guesses a state, they should be able to enter the full state name or the state symbol using any mixture of uppercase or lowercase letters.
Clues – The user will be provided a series of 9 clues, in random order, from the following list. The blanks below will contain the appropriate information obtained from the data file. The program must use these 9 clues.
The first letter of the state is ___.
The last letter of the state is ___.
The first letter of the state capital is ___.
The last letter of the state capital is ___.
The state’s rank in population, where 1 is the largest, is ___.
The state’s rank in size (or area), where 1 is the largest, is ___.
The state is in the following time zone(s): ___
The state’s nickname is ___;
The state is bordered by the following states: ___.
Data file below:
Program Requirements: 1) Creating a class: The program should define class StateGame (or pick your own name) according to the following class diagram.
? Use the data members indicated and member functions indicated. Additional data members and member functions can be added if you wish. ? All data members must be private. All member functions must be public.
? Once the state information has been accessed using ReadLine( ), do not open or read from the data file again. All state information should then be accessed using accessor functions (Get…( )), not by reading the file again. Do not define State, Symbol, etc., in main. Access them from the class.
? Do not display values (using cout, for example) from any member function. Access the data using accessor functions and display any desired values within main.
? Use a member functions to get the Score and to update the Score. Do not define Score in main.
? Include a constructor function which initializes Score to 100. ? Use separate header and implementation files for the class (StateGame.h and StateGame.cpp)
e Edit Format View Help State Symbol Capital Pop Size Zone Nickname Bordering States 111111 000000000011111111112222222222333 33 33 33 555 55556666666666 77 77 77 88 888 888 99 99 99 900 0000 012345678901 123456789012 456789012345678 9012 3456 7890123 456 9012 34567890123456789012345 Alabama AL Montgomer 23 30 CST Heart of Dixie FL, GA,MS, TN Alaska AK Juneau 48 AKST Last Frontier none Arizona AZ Phoenix 15 MST Grand Canyon State CA,CO, NM, NV,UT Arkansas AR Little Rock 32 29 CST Natural State LA, MO, MS, OK,TN, TX California CA Sacramento PST Golden State NV, OR,AZ Colorado CO Denver 22 MST Centennial State KS, NE, NM, OK,UT,WY,AZ Connecticut CT Hartford 29 48 EST Constitution State MA, NY, RI First State Delaware DE Dover 45 49 EST MD, NJ,PA Florida FL. Tallahassee 22 EST/CST Everglade State GA,AL Georgia GA Atlanta 24 EST Peach State NC,SC,TN, FL, AL Hawaii HI Honolulu 43 HST Aloha State none Idaho ID Boise 39 14 PST/MST Gem State MT, NV,OR,UT, WA,WY Illinois IL Springfield 25 CST and of Lincoln IN,KY, MO,WI,IA Indiana IN Indianapolis 16 38 EST/CST Hoosier State IL,MI,KY,OH Iowa IA Des Moines 30 26 CST Hawkeye State IL, WI,MO,NE,SD, MN Kansas Topeka 34 15 CST/MST America's Bread Basket MO,NE,OK,CO Kentucky Frankfort 26 37 EST/CST Bluegrass State M0,00H,TN,VA,WV, IL,IN Louisiana LA Baton Rouge 25 31 CST Pelican State MS,TX,AR ne Tree State Maine ME Augusta 41 39 EST NH PA,VA,WV,DE Maryland Annapolis 19 42 EST Chesapeake State Massachusetts MA Boston 14 EST Baked Bean State NH, VT,CT, RI,NY Michigan MI Lansing 10 11 EST/CST Great L akes State OH,WI,IN Minnesota MN Saint Paul 21 12 CST North Star State ND, SD,WI,IA Mississippi MS Jackson 31 32 CST Hospitality State AL,AR,LA, TN Missouri Jefferson City 18 21 CST Show-Me State IA,NE,KS, OK,AR, TN,KY,IL. Montana Helena MST Big Sky Country ND, SD,WY,ID Nebraska NE Lincoln 37 16 CST/MST Cornhusker State SD,WY,CO, KS, MO, IA CA AZ, UT ID, OR Nevada NV Carson City 35 PST/MST Silver State New Hampshire NH Concord 42 EST Granite State ME,MA,VT New Jersey NJ Trenton 11 47 EST Garden State NY,PA,DE New Mexico Santa Fe 36 MST OK, TX,UT,CO,AZ NM nd of Enchantment New York NY Albany 27 EST Empire State NJ, PA,CT, MA,VT North Carolina NC Raleigh 28 EST Tar Heel State VA,SC,GA,TN North Dakota ND Bismarck 47 19 CST/MST Peace Garden State MN,SD,MT Ohio OH Columbus 34 EST Buckeye State PA,WV,KY,IN,MI OK Oklahoma City 28 20 CST Sooner State TX,KS,MO,AR,NM,CO Oklahoma Oregon OR Salem 27 PST/MST Beaver State WA,ID,NE,CA Pennsylvania PA Harrisburg 33 EST Keystone State WV,NY, NJ, MD,OH,DE Rhode Island RI Providence 43 50 EST Ocean State MA,CT South Carolina SC Columbia 24 EST Palmetto State NC,GA South Dakota SD Pierre 46 17 CST/MST Mount Rushmore State ND, MN,IA,NE, WY, MT Tennessee TN Nashville 17 36 EST/CST Volunteer State VA, KY, NC,GA,AL,MS,AR,MO Texas Austin CST/MST Lone Star State OK,AR, LA, NM Utah Salt Lake City 33 13 MST Beehive State WY,ID,CO, NM,AZ,NV Vermont Montpelier 49 45 EST Green Mountain State NH, MA,NY WV,NC,TN,KY, MD Virginia VA Richmond 12 35 EST Old Dominion Washington WA. Olympia 13 18 PST Evergreen State ID,OR. PA, MD,VA,KY,OH Charleston 38 41 EST West Virginia WV Mountain State Wisconsin WI Madison 20 23 CST Badger State MI,IL,IA,MN Wyoming Cheyenne 50 10 MST Cowboy State MT, SD,NE,CO,UT,IDExplanation / Answer
Solution:
/* To display task names and state for all running tasks. */
#include <windows.h>
#include <iostream>
#include <stdio.h>
#include <comdef.h>
// Include the task header file.
#include <taskschd.h>
# pragma comment(lib, "taskschd.lib")
# pragma comment(lib, "comsupp.lib")
using namespace std;
int __cdecl wmain()
{
clrscr();
// ------------------------------------------------------
// Initialize COM.
HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
if( FAILED(hr) )
{
printf(" CoInitializeEx failed: %x", hr );
return 1;
}
// Set general COM security levels.
hr = CoInitializeSecurity(
NULL,
-1,
NULL,
NULL,
RPC_C_AUTHN_LEVEL_PKT_PRIVACY,
RPC_C_IMP_LEVEL_IMPERSONATE,
NULL,
0,
NULL);
if( FAILED(hr) )
{
printf(" CoInitializeSecurity failed: %x", hr );
CoUninitialize();
return 1;
}
// ------------------------------------------------------
// Create an instance of the Task Service.
ITaskService *pService = NULL;
hr = CoCreateInstance( CLSID_TaskScheduler,
NULL,
CLSCTX_INPROC_SERVER,
IID_ITaskService,
(void**)&pService );
if (FAILED(hr))
{
printf("Failed to CoCreate an instance of the TaskService class: %x", hr);
CoUninitialize();
return 1;
}
// Connect to the task service.
hr = pService->Connect(_variant_t(), _variant_t(),_variant_t(), _variant_t());
if( FAILED(hr) )
{
printf("ITaskService::Connect failed: %x", hr );
pService->Release();
CoUninitialize();
return 1;
}
// Get the running tasks.
IRunningTaskCollection* pRunningTasks = NULL;
hr = pService->GetRunningTasks(TASK_ENUM_HIDDEN, &pRunningTasks);
pService->Release();
if( FAILED(hr) )
{
printf("Cannot get Root Folder pointer: %x", hr );
CoUninitialize();
return 1;
}
LONG numTasks = 0;
hr = pRunningTasks->get_Count(&numTasks);
if( numTasks == 0 )
{
printf(" No Tasks are currently running" );
pRunningTasks->Release();
CoUninitialize();
return 1;
}
printf(" Number of running tasks : %d", numTasks );
TASK_STATE taskState;
for(LONG i=0; i < numTasks; i++)
{
IRunningTask* pRunningTask = NULL;
hr = pRunningTasks->get_Item( _variant_t(i+1), &pRunningTask );
if( SUCCEEDED(hr) )
{
BSTR taskName = NULL;
hr = pRunningTask->get_Name(&taskName);
if( SUCCEEDED(hr) )
{
printf(" Task Name: %S", taskName);
SysFreeString(taskName);
hr = pRunningTask->get_State(&taskState);
if (SUCCEEDED (hr) )
printf(" State: %d", taskState);
else
printf(" Cannot get the registered task state: %x", hr);
}
else
{
printf(" Cannot get the registered task name: %x", hr);
}
pRunningTask->Release();
}
else
{
printf(" Cannot get the registered task item at index=%d: %x", i+1, hr);
}
}
pRunningTasks->Release();
CoUninitialize();
return 0;
}
To display task names and state for all the tasks in a task folder.
#include <windows.h>
#include <iostream>
#include <stdio.h>
#include <comdef.h>
// Include the task header file.
#include <taskschd.h>
# pragma comment(lib, "taskschd.lib")
# pragma comment(lib, "comsupp.lib")
using namespace std;
int __cdecl wmain()
{
// ------------------------------------------------------
// Initialize COM.
HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
if( FAILED(hr) )
{
printf(" CoInitializeEx failed: %x", hr );
return 1;
}
// Set general COM security levels.
hr = CoInitializeSecurity(
NULL,
-1,
NULL,
NULL,
RPC_C_AUTHN_LEVEL_PKT_PRIVACY,
RPC_C_IMP_LEVEL_IMPERSONATE,
NULL,
0,
NULL);
if( FAILED(hr) )
{
printf(" CoInitializeSecurity failed: %x", hr );
CoUninitialize();
return 1;
}
// ------------------------------------------------------
// Create an instance of the Task Service.
ITaskService *pService = NULL;
hr = CoCreateInstance( CLSID_TaskScheduler,
NULL,
CLSCTX_INPROC_SERVER,
IID_ITaskService,
(void**)&pService );
if (FAILED(hr))
{
printf("Failed to CoCreate an instance of the TaskService class: %x", hr);
CoUninitialize();
return 1;
}
// Connect to the task service.
hr = pService->Connect(_variant_t(), _variant_t(),_variant_t(), _variant_t());
if( FAILED(hr) )
{
printf("ITaskService::Connect failed: %x", hr );
pService->Release();
CoUninitialize();
return 1;
}
// ------------------------------------------------------
// Get the pointer to the root task folder.
ITaskFolder *pRootFolder = NULL;
hr = pService->GetFolder( _bstr_t( L"\") , &pRootFolder );
pService->Release();
if( FAILED(hr) )
{
printf("Cannot get Root Folder pointer: %x", hr );
CoUninitialize();
return 1;
}
// -------------------------------------------------------
// Get the registered tasks in the folder.
IRegisteredTaskCollection* pTaskCollection = NULL;
hr = pRootFolder->GetTasks( NULL, &pTaskCollection );
pRootFolder->Release();
if( FAILED(hr) )
{
printf("Cannot get the registered tasks.: %x", hr);
CoUninitialize();
return 1;
}
LONG numTasks = 0;
hr = pTaskCollection->get_Count(&numTasks);
if( numTasks == 0 )
{
printf(" No Tasks are currently running" );
pTaskCollection->Release();
CoUninitialize();
return 1;
}
printf(" Number of Tasks : %d", numTasks );
TASK_STATE taskState;
for(LONG i=0; i < numTasks; i++)
{
IRegisteredTask* pRegisteredTask = NULL;
hr = pTaskCollection->get_Item( _variant_t(i+1), &pRegisteredTask );
if( SUCCEEDED(hr) )
{
BSTR taskName = NULL;
hr = pRegisteredTask->get_Name(&taskName);
if( SUCCEEDED(hr) )
{
printf(" Task Name: %S", taskName);
SysFreeString(taskName);
hr = pRegisteredTask->get_State(&taskState);
if (SUCCEEDED (hr) )
printf(" State: %d", taskState);
else
printf(" Cannot get the registered task state: %x", hr);
}
else
{
printf(" Cannot get the registered task name: %x", hr);
}
pRegisteredTask->Release();
}
else
{
printf(" Cannot get the registered task item at index=%d: %x", i+1, hr);
}
}
pTaskCollection->Release();
CoUninitialize();
return 0;
getch();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.