I need help programming this in c++ our company has been asked to develop a prog
ID: 3712870 • Letter: I
Question
I need help programming this in c++
our company has been asked to develop a program for the Brain Readiness Academic Training Institute (BRATI) that will help their BRATI elementary students learn the order of United States Presidents as well as some information about them. Write a C++ console application that performs the tasks as spelled out below:
In this project, you will implement a bag class that will store a vector of presidents. The Program will display a president name and then ask you what the presidential number is. For example, "What is the presidential number of BarackObama?". Your reply should be 44. At that point in time the program will display:
Time he lived
date he took office
date he left office
his party
previous office held
the name of his vice president
If you type an incorrect value for the presidential number, the program will display an error message and the correct presidential number, incorrect responses and total guesses.
The User will click -1 to exit the program if they do not want to continue guessing presidential numbers.
Your program should use ASCII colors to set background and foreground (font) colors to reflect correct and incorrect responses. See FAQ #8 for details.
Files You Will Create:
Presidents.h - there is an attached copy of Presidents.h that you can us as a start to organize your variables and methods. You will either use as is or modify it.
Presidents.cpp - fully define methods defined in Presidents.h
PresidentsGame.cpp - will create a stack of the president class, show a "game" menu and return information to user. (See below for output examples.)
Presidents.h should contain everything you need to store and access president data. Note the overloaded functions (methods in OOP terminology) at the bottom of the header file. Take a look at how the baccount.cpp file implemented the == operator on page 329. You will be doing something similar. There is also something new, friend functions. In general a friend function is not part of the class but has access to the class private data. Like the neighbor that feels free to walk into your house and get a beer out of the refrigerator without asking. ;) You can look up "C++ friends function" on the Internet.
The main program main function should be an infinite loop that puts out instructions and sets the game in motion. Here are some possible functions you can use to help break things apart:
void instructions();
void totals(int& correctRef, int &wrongRef);
void loadPresidents(Set & bagOfPresidents);
int getGuess(Presidents& pres);
void getTerm(int rand);
// this is a little extra, one president ran in two different nonconsecutive terms,
// see if you can figure out how to identify his terms
void playPresidents();
Again, these are just suggestions, this is your program, so you can break it apart however you want.
Explanation / Answer
#ifndef PRESIDENTPRESIDENT_H
#define PRESIDENT_H
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
class Bag
{
public:
president(string Name)
{mName=Name;}
virtual void printStats()
{
cout<<"Name:"<<mName<<endl;
}
virtual void save(ofstream& outFile)
{
outFile<<"Name:"<<mName<<endl;
}
protected:
string mName;
};
#endif
///main().cpp
#include<iostream>
#include<fstream>
#include<vector>
#include<string>
#include"president.h"
using namespace std;
int main()
{
vector<presidents*> database;
bool quit=false;
ofstream outFile("out.txt");
presidents* pre[50];
int input,select1,j,lived,dol,doj,prenum,num;
string Name;string party;string vicename;string preoff;
while(!quit)
{
cout<<"Database size:"<<database.size()<<endl;
cout<<"Database contains:";
for(int k=0;k<database.size();k++)
{
pre[k]->printStats();
cout<<endl<<endl;
}
cout<<" 1.Exit 2.Add a presidents 3.Delete a presidents 4.Detail of a presidents ";
cin>>select1;
cout<<endl;
switch(select1)
{
case 1:
cout<<"/nExiting............";
quit=true;
break;
case 2:
cout<<" the presidential number :";
cin>>prenum;
cout<<" Enter name:";
getline(cin,Name);
cout<<" Time he lived:";
cin>>lived;
cout<<" date he took office:";
cin>>doj;
cout<<" date he left office:";
cin>>dol;
cout<<" his party:";
cin>>party;
cout<<" previous office held:";
getline(cin,preoff);
cout<<" the name of his vice president:";
getline(cin,vicename);
emp[j]=new president(firstName,lastName,lived,doj,dol,party,pre,vicename);
database.push_back(emp[j]);
pre[j]->save(outFile);
j++;
break;
case 3:
cout<<"enter last name of president to be deleted:";
getline(cin,search);
for(int l=0;l<database.size();l++)
{
if(database[l]->getLastName()==search)
{
database.erase(database.begin()+l);
break;
}
}
case 4:
cout<<" Name:"<<mName<<endl;
cout<<" what the presidential number is:";
cin>>num;
if(num==prenum)
{
cout<<" date he took office:"<<doj;
cout<<" date he left office:"<<dol;
cout<<" his party:"<<party;
cout<<" previous office held:"<<preoff;
cout<<" the name of his vice president:"<<vicename;
}
else
{
cout<<" Error"<<prenum;
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.