eraggo (144) Feb 11, 2013 at 4:52am
Please, share to us what you have this far of following: main program and class declaration. Seems you only shared (accidentally?) header file. |
These are the other things given to us. Please if you can do anything help me because the test is very important.
This program uses a structure to hold data about a rectangle. Fill in missing code segments.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
#include <iostream>
#include <iomanip>
using namespace std;
// array_struct uses a structure to hold data about a rectangle
// FILL IN CODE TO define a structure named rectangle which has
// members length, width, area, and perimeter all of which are floats
int main()
{
// Fill IN CODE to declare a rectangle variable named box
cout << "Enter the length of a rectangle: ";
// FILL IN CODE to read in the length member of box
cout << "Enter the width of a rectangle: ";
// FILL IN CODE to read in the width member of box
cout << endl << endl;
// FILL IN CODE to compute the area member of box
// FILL IN CODE to compute the perimeter member of box
cout << fixed << showpoint << setprecision(2);
// FILL IN CODE to output the area with an appropriate message
// FILL IN CODE to output the perimeter with an appropriate message
return 0;
}
|
This program demonstrates partially initialized structure variables. Fill in missing code segments. You will need to be able to initialize the first three structure members of two structure variables while leaving the last two members un-initialized. You will also be required to add read statements involving one of the structure members.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
#include <iostream>
#include <string>
using namespace std;
// init_struct demonstrates partially initialized structure variables
struct taxPayer
{
string name;
long int socialSecNum;
float taxRate;
float income;
float taxes;
};
int main()
{
// Fill in code to initialize a structure variable named citizen1 so that
// the first three members are initilized. Assume the name is Tim
// McGuiness,the social security number is 255871234, and the tax rate is .35
// Fill in code to initialize a structure variable named citizen2 so that
// the first three members are initialized. Assume the name is John Kane,
// the social security number is 278990582, and the tax rate is .29
cout << fixed << showpoint << setprecision(2);
// calculate taxes due for citizen1
// Fill in code to prompt the user to enter this year's income for the citizen1
// Fill in code to read in this income to the appropriate structure member
// Fill in code to determine this year's taxes for citizen1
cout << "Name: " << citizen1.name << endl;
cout << "Social Security Number: " << citizen1.socialSecNum << endl;
cout << "Taxes due for this year: $" << citizen1.taxes << endl << endl;
// calculate taxes due for citizen2
// FILL IN CODE to prompt the user to enter this year's income for citizen2
// FILL IN CODE to read in this income to the appropriate structure member
// FILL IN CODE to determine this year's taxes for citizen2
cout << "Name: " << citizen2.name << endl;
cout << "Social Security Number: " << citizen2.socialSecNum << endl;
cout << "Taxes due for this year: $" << citizen2.taxes << endl << endl;
return 0;
}
|
Like the first two labs, you are asked to fill in missing code involving a structure declaration. However, in this lab you are also required to define an array of structures. In addition, you must add a looping statement at the end of the program. In the second exercise, you are asked to address an indexing issue regarding arrays (i.e., if we have a list indexed by 1,2,3, . . . then we have to compensate for the fact that the array holding this information must start with 0). Of course, this is something that has been addressed repeatedly in earlier lessons. However, it is useful for you to recall this point several times throughout the course.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
#include <iostream>
#include <iomanip>
using namespace std;
// array_struct demonstrates how to use an array of structures
// Fill in code to define a structure called taxPayer that has three
// members: taxRate, income, and taxes -- each of type float
int main()
{
// Fill in code to declare an array named citizen which holds
// 5 taxPayers structures
cout << fixed << showpoint << setprecision(2);
cout << "Please enter the annual income and tax rate for 5 tax payers: ";
cout << endl << endl << endl;
for(int count = 0;count < 5;count++)
{
cout << "Enter this year's income for tax payer " << (count + 1);
cout << ": ";
// Fill in code to read in the income to the appropriate place
cout << "Enter the tax rate for tax payer # " << (count + 1);
cout << ": ";
// Fill in code to read in the tax rate to the appropriate place
// Fill in code to compute the taxes for the citizen and store it
// in the appropriate place
cout << endl;
}
cout << "Taxes due for this year: " << endl << endl;
// Fill in code for the first line of a loop that will output the
// tax information
{
cout << "Tax Payer # " << (index + 1) << ": " << "$ "
<< citizen[index].taxes << endl;
}
return 0;
}
|
Like the first three labs, you are asked to fill in missing code involving structure declarations. The first is a structure named dimensions that contains two members of type float. The second is a structure named rectangle that contains two float members and a third member of type dimensions. In other words, you should nest a dimensions structure inside of a rectangle structure. In the second exercise, you are asked to modify the program so that the rectangle structure has structure variables for both of its members. The third exercise requires structure variables to be passed as arguments to a pair of functions.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
#include <iostream>
#include <iomanip>
using namespace std;
// nestedRect_struct uses a structure to hold data about a rectangle
// It calculates the area and perimeter of a box
// Fill in code to define a structure named dimensions that
// contains 2 float members, length and width
// Fill in code to define a structure named rectangle that contains
// 3 members, area, perimeter, and sizes. area and perimeter should be
// floats, whereas sizes should be a dimensions structure variable
int main()
{
// Fill in code to declare a rectangle structure variable named box.
cout << "Enter the length of a rectangle: ";
// Fill in code to read in the length to the appropriate location
cout << "Enter the width of a rectangle: ";
// Fill in code to read in the width to the appropriate location
cout << endl << endl;
// Fill in code to compute the area and store it in the appropriate
// location
// Fill in code to compute the perimeter and store it in the
// appropriate location
cout << fixed << showpoint << setprecision(2);
cout << "The area of the rectangle is " << box.attributes.area << endl;
cout << "The perimeter of the recangle is " << box.attributes.perimeter
<< endl;
return 0;
}
|