Question

C++ #include            // needed for Cin and Cout #include            //...

C++

#include            // needed for Cin and Cout
#include            // needed to manipulate strings
#include            // needed for output formatting
using namespace std;

/*********************************
* struct definition
**********************************/
struct FootballTeam
{
string team; // team name
string opponent; // opponent name
int teamScore; // teams score
int oppoScore; // opponents score
};

/*********************************
* prototypes here
**********************************/
void testStruct01A();
/***************************************
* there are no global variables
***************************************/

int main()
{
testStruct01A();

system("pause");
return 0;
}
void testStruct01A()
{
cout << "**********************************\n";
cout << "* in void testStruct01A() *\n";
cout << "**********************************\n\n\n";

// create a FootballTeam object
FootballTeam fbt;

// load the FootballTeam object
cout << "enter home team name: ";
cin >> fbt.team;
cout << "enter opponent team name: ";
cin >> fbt.opponent;
cout << "enter home team score ";
cin >> fbt.teamScore;
cout << "enter opponent team score: ";
cin >> fbt.oppoScore;

// print the FootballTeam object
cout << " ********** AFC East **********\n";
cout << "Home Team " << fbt.team << "\n";
cout << "Opponent team " << fbt.opponent << "\n";
cout << "Home Team score " << fbt.teamScore << "\n";
cout << "Opponent team score " << fbt.oppoScore << "\n\n\n";

}

Assignment is to create, initialize (using cin), and print (using cout) a struct object

A Struct named FootballTeam has already been defined for you

All testing will be done in a function named

             void testStruct01A()

this function is called from main

in main()

call the function void test01A()

in the function void test01A()

1. create a FootballTeam object   
2. using 'cin', load the FootballTeam object  
3. using 'cout', display (print) the FootballTeam object
4. output should look like the following

********** AFC East **********

Home Team              XXXXXXXXXXXXXXXXXXXXXXXX

Opponent team          XXXXXXXXXXXXXXXXXXXXXXXX

Home Team score        XXXXXXXXXXXXXXXXXXXXXXXX

Opponent team score    XXXXXXXXXXXXXXXXXXXXXXXX

NOTE: you should be able to enter more than one

       Than one word for a team’s name (use getline)                

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The provided contains many errors. A clean version of the code is as follows:

//NOTE: all the colored texts shows the changes that has been done to your code.

#include <iostream> // used for the cin and cout, basically the Input Output Streams
#include <string> // used to manipulate the strings
#include <iomanip> // used for output formatting
using namespace std;
/*********************************
* struct definition
**********************************/
struct FootballTeam
{
string team; // team name
string opponent; // opponent name
int teamScore; // teams score
int oppoScore; // opponents score
};
/*********************************
* prototypes here
**********************************/
void testStruct01A();
/***************************************
* there are no global variables
***************************************/
int main()
{
testStruct01A();
system("pause");//works only in Windows.
//To make it work in Linux Based systems, you'll need to have the next line given
//system("read -p 'Press Enter to continue...' var");
//Remove the comments marker "//" on linux based systems
return 0;
}
void testStruct01A()
{
cout << "**********************************\n";
cout << "* in void testStruct01A() *\n";
cout << "**********************************\n\n\n";
// create a FootballTeam object
FootballTeam fbt;
// load the FootballTeam object
cout << "enter home team name: ";
getline(cin,fbt.team);//Remember to use getline function and pass parameters as cin and the object
//it is a part of string header. Extracts characters from input stream (cin) and appends it to the object passed
//when we use a normal cin, it will take only the first word of the name and ignore the rest.
fflush(stdin);//this is to clear the input buffer so that it doesn't go to a counter-intuitive state.
cout << "enter opponent team name: ";
getline(cin,fbt.opponent);//again, we use the getline function as we should not skip out the rest of the name
fflush(stdin);
cout << "enter home team score ";
cin >> fbt.teamScore;
cout << "enter opponent team score: ";
cin >> fbt.oppoScore;
// print the FootballTeam object
cout << "**********AFC East**********" << endl;
cout << "Home Team " << fbt.team << "\n"; //Displaying the home team name
cout << "Opponent team " << fbt.opponent << "\n"; //displaying the opponent team name
cout << "Home Team score " << fbt.teamScore << "\n"; //displaying the home team score
cout << "Opponent team score " << fbt.oppoScore << "\n\n\n"; // displaying the opponent team score
}

SCREENSHOTS:

OUTPUT:

---------------------------------------------------------------------

Please leave a thumbs up if you are satisfied with the answer, or if you have any queries or doubts regarding the code, please feel free to drop it in the comments section below. We will be happy to assis you anytime. Thank You! Keep Chegging!! :)

Add a comment
Know the answer?
Add Answer to:
C++ #include            // needed for Cin and Cout #include            //...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • part 1(do not write on note book and before send program compile it) void testStruct01() this...

    part 1(do not write on note book and before send program compile it) void testStruct01() this function is called from main in main() call the function void test01() in the function void test01() 1. create a FootballTeam object    2. using 'cin', load the FootballTeam object   3. using 'cout', display (print) the FootballTeam object 4. output should look like the following         ********** AFC East ********** Home Team              XXXXXXXXXXXXXXXXXXXXXXXX Opponent team          XXXXXXXXXXXXXXXXXXXXXXXX Home Team score        XXXXXXXXXXXXXXXXXXXXXXXX Opponent team score   XXXXXXXXXXXXXXXXXXXXXXXX part...

  • #include <iostream> #include <cstdlib> #include <time.h> #include <string> using namespace std; int main() { srand(time (0));...

    #include <iostream> #include <cstdlib> #include <time.h> #include <string> using namespace std; int main() { srand(time (0)); int number, guess, response, reply; int score = 0 number = rand() % 100 + 1; do { do { cout << "Enter your guess "; cin >> guess; score++; if (guess < number) cout << guess << " is too low! Enter a higher number. "; else if (guess > number) cout << guess << " is too high! Enter a lower number....

  • This is just a partial C++ code. I am having a problem with the getline(cin, variable)...

    This is just a partial C++ code. I am having a problem with the getline(cin, variable) statement of my code. Please run the code for yourself and see that it doesn't let you enter the full name. It skips the prompt to enter the name and goes straight to the next cout statement. I can't use cin alone because I need to capture and store both the first name followed by space followed by last name. I was trying to...

  • Please fill in this code to reverse a linked list: (written in C/C++) #include #include #include...

    Please fill in this code to reverse a linked list: (written in C/C++) #include #include #include using namespace std; /* Link list node */ struct Node { int data; // your code here }; /* Function to reverse the linked list */ static void reverse(struct Node** head_ref) { // your code here } /* Function to push a node */ void push(struct Node** head_ref, int new_data) { // your code here } /* Function to print linked list */ void...

  • Please fill in the code to reverse a linked list. IN C++ #include <stdio.h> #include <stdlib.h>...

    Please fill in the code to reverse a linked list. IN C++ #include <stdio.h> #include <stdlib.h> #include <iostream> using namespace std; /* Link list node */ struct Node { int data; // your code here }; /* Function to reverse the linked list */ static void reverse(struct Node** head_ref) { // your code here } /* Function to push a node */ void push(struct Node** head_ref, int new_data) { // your code here } /* Function to print linked list...

  • rewrite this c code in python #include <iostream> using std::cout; using std::cin; using std::endl; int charClass;...

    rewrite this c code in python #include <iostream> using std::cout; using std::cin; using std::endl; int charClass; char lexeme[100]; char str[200]; char nextChar; const int LETTER = 0; const int DIGIT = 1; const int UNKNOWN = -1; const int OPAREN = 2; const int CPAREN = 3; const int PLUS = 4; const int MINUS = 5; const int MUL = 6; const int DIV = 7; const int ID_CODE = 100; const int PLUS_CODE = 101; const int MINUS_CODE...

  • Edit this C++ code to show the output as well. #include<iostream> #include<cstring> using namespace std; class...

    Edit this C++ code to show the output as well. #include<iostream> #include<cstring> using namespace std; class Product { private:    // private variables    int id_number;    char pDescription[40];    int mId;    double productPrice;    double productMarkUp;    int qty; public:    // constructor    Product() {        id_number = 0;        strcpy_s(pDescription, "");        mId = 0;        productPrice = 0.0;        productMarkUp = 0.0;        qty = 0;    }   ...

  • I am getting an error that the variable num was not declared in the scope on...

    I am getting an error that the variable num was not declared in the scope on the line of code that has; while(num != 5). Do you know how to fixe this error? #include <iostream> #include <iomanip> #include <string> #include<fstream> #include <cstring> using namespace std; //Declare the structure struct Games { string visit_team; int home_score; int visit_score; }; // Function prototypes int readData(Games *&stats); int menu(); void pickGame(Games *&stats, int size); void inputValid (Games *&stats, int size); void homeTotal(Games *&stats,...

  • Using C++ write the following program: 1) For the song program below, on a separate line...

    Using C++ write the following program: 1) For the song program below, on a separate line write a function to quickly print the list of Streaming Services in your Song class, do not modify the program. 2). The Duration in your Song class contains minutes and seconds. Create a data structure called Duration to group the data, do not modify the program but with it on a separate line. #include<iostream> using namespace std; struct Song {    string song_title;   ...

  • Change the the following C++ codes to list the "marks" reported Alphabetically. --------------------------------------------------------------------------------------------------------- #include <iostream> #include<string.h>...

    Change the the following C++ codes to list the "marks" reported Alphabetically. --------------------------------------------------------------------------------------------------------- #include <iostream> #include<string.h> using namespace std; void display(int marks[10]); int main() { int marks[10]; int i;x for (i=0; i<10; i++) { cout << "Enter marks : "; cin >> marks[i]; } display(marks); return 0; } // Create the function sort to sort the marks in alphabetical order void display(int marks[10]) { cout <<"Displaying marks in Ascending Order " << endl; for (int i = 0; i <10;...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT