Project #15876 - C++

 Write a program that uses a class rectangle in a separate header file. 

The class has data members for length, width, area, and perimeter.  The length and width can be set by the user, but the area and perimeter can not be set by the user (their values depend on the values of length and width).  Include 2 other member functions that separately calculates the perimeter and area of the rectangle.  Let the user be able to separately get the value of all 4 data fields.  Include a constructor, that does not take any arguments, but initializes all the data fields, the length and width to 1, and the area and perimeter calculated as in the two calculate functions. 

The main program file will declare a rectangle object, call the member functions to calculate the perimeter and area, and then get and print out the results.

Use the following ex5-1.cpp and create the corresponding rectangle5-1.h header file.


This program will create a rectangle object
*/
#include<iostream>
#include"rectangle5-1.h"
using namespace std;

void main()
{
    rectangle51 r;  // write constructor
    float len, wid;
    cout << "Enter length:  ";
    cin >> len;
    r.setlength(len); // write functions
    cout << "Enter width:  ";
    cin >> wid;
    r.setwidth(wid);
    r.calcarea();
    r.calcperimeter();
    cout << "Rectangle's length = " << r.getlength() << endl;
    cout << "Rectangle's width = " << r.getwidth() << endl;
    cout << "Rectangle's area = " << r.getarea() << endl;
    cout << "Rectangle's perimeter = " << r.getperimeter() << endl;
}

 

 

4-13f. Here is part 4-13 part d, modify the code to produce parts b (separate header file student4-13.h for the structure definition, see fields in code to see data fields) and parts e and f (separate function for the printing of the array and pass the address of the array to a student pointer that will increment through the array, printing the student address label by accessing the fields through the arrow operator and making the for loop into a pointer comparison while loop).

**     d.    with an array of student structures

**     b.    with the structure definition in a separate header file
*      e.    with a function to print the array
**     f.    with a pass by reference (pointer to the array) to the function (using the arrow operator), using the pointer comparison while loop



This program will make a student structure
*/
#include<iostream>
#include"student4-13.h"   // define student and address structures
using namespace std;

void main()
{
    student s[2];  // array of two student structures
    int i, j;

    for (i = 0; i < 2; i++)
    {
    cout << "Enter Student First Name:  ";
    cin >> s[i].first;   // input into the ith student's first name field
    cout << "Enter Student Last Name:  ";
    cin.ignore(1, '\n');   // clear enter
    cin >> s[i].last;
    cout << "Enter Street Address:  ";
    cin.ignore(1, '\n');
    cin.getline(s[i].home.street, sizeof(s[i].home.street), '\n'); /* whole line for street*/
    cout << "Enter City:  ";
    cin.getline(s[i].home.city, sizeof(s[i].home.city), '\n');
    cout << "Enter State (ex. NY):  ";
    cin >> s[i].home.state;
    cout << "Enter Zip Code:  ";
    cin.ignore(1, '\n');
    cin >> s[i].home.zip;
    cout << "Enter Class Year:  ";
    cin >> s[i].year;
    cout << endl;
    }

            // pass student array to separate function - student pointer

    for (j = 0; j < 2; j++) // change to while pointer comparison loop
    {
    cout << "\n\n";    // change to print fields using pointer and arrow operator
    cout << s[j].first << " " << s[j].last << "  " << s[j].year << endl;
    cout << s[j].home.street << endl;
    cout << s[j].home.city << ", " << s[j].home.state << "  " << s[j].home.zip << endl;
    }
}

 


project #2

Subject Computer
Due By (Pacific Time) 11/03/2013 12:00 am
Report DMCA
TutorRating
pallavi

Chat Now!

out of 1971 reviews
More..
amosmm

Chat Now!

out of 766 reviews
More..
PhyzKyd

Chat Now!

out of 1164 reviews
More..
rajdeep77

Chat Now!

out of 721 reviews
More..
sctys

Chat Now!

out of 1600 reviews
More..
sharadgreen

Chat Now!

out of 770 reviews
More..
topnotcher

Chat Now!

out of 766 reviews
More..
XXXIAO

Chat Now!

out of 680 reviews
More..
All Rights Reserved. Copyright by AceMyHW.com - Copyright Policy