Cartesian Data/Vector homework

Social responsibilities of News Channels
June 21, 2017
List three regulatory and reporting requirements that a listed company
June 21, 2017

Cartesian Data/Vector homework

Cartesian Data/Vector homework
Setup
You will need the class files:
~/cs162/baseCode/classes/incl/complex0.h
~/cs162/baseCode/classes/src/complex0.cpp
and the Homework Exercise files:
~/cs162/lu07/7_assign_code/hw02/incl/fns02.h
~/cs162/lu07/7_assign_code/hw02/src/fns02.cpp
~/cs162/lu07/7_assign_code/hw02/src/drvr02.cpp
Problem Statement
Define a complex class so that the following function can use it with correct results:
#include <iostream>
using namespace std;
#include “../incl/complex0.h” //to avoid confusion with complex.h
void demoComplex()
{
complex a( 3.0, 4.0 ); // initialize to (3, 4i)
complex c;
cout << “Enter a complex number (q to quit):n” ;
while( cin >> c )
{
cout << “c is ” << c << ‘n’ ;
cout << “complex conjugate is ” << ~c << ‘n’ ;
cout << “a is ” << a << ‘n’ ;
cout << “a + c is ” << a + c << ‘n’ ;
cout << “a – c is ” << a – c << ‘n’ ;
cout << “a * c is ” << a * c << ‘n’ ;
cout << “2 * c is ” << 2 * c << ‘n’ ;
cout << “c * 2 is ” << c * 2 << ‘n’ ;
cout << “Enter a complex number (q to quit):n” ;
}
cout << “Done!n” ;
}
Solving the Problem
General Approach
Declare the class in the class header file. Specify the data members needed, the constructors, inspectors, mutators, and facilitators indicated by the problem statement and the requirements of the demonstration function. Declare operator overloads as needed to satisfy the needs of the demonstration function. Overloads should be non-member auxiliary functions, not member or friend functions. Declare public member functions needed by the overload functions.
Define the member functions, testing each as you define it. Use the ~/cs162/lu07/7_assign_code/hw02/src/drvr02.cpp file for this, as well as executing the demonstration function.)
Declare and define the demonstration function as specified in the Problem Statement.
Specific Approach
Note that you have to overload the << and >> operators for this class. Use const wherever warranted – specifically with inspector functions, and Complex objects passed as reference parameters.
Provide overloads for both n * c and c * n
A sample run of the demonstration function might produce this output:
Enter a complex number (q to quit):
real: 10
imaginary: 12
c is (12, 12i)
complex conjugate is (10, -12i)
a is (3, 4i)
a + c is (13, 16i)
a – c is (-7, -8i)
a * c is (-18, 76i)
2 * c is (20, 24i)
c * 2 is (20, 24i)
Enter a complex number (q to quit):
real: q
Done!
Setup
You will need the class files:
~/cs162/baseCode/classes/incl/myvector.h
~/cs162/baseCode/classes/src/myvector.cpp
and the Homework files
~/cs162/lu07/7_assign_code/hw01/incl/fns01.h
~/cs162/lu07/7_assign_code/hw01/src/fns01.cpp
~/cs162/lu07/7_assign_code/hw01/src/drvr01.cpp
Problem Statement
Modify the Vector class header and implementation files so that the magnitude and angle are no longer stored as data components. Instead, they should be calculated on demand when the magval() and angval() methods are called.
Solving the Problem
General approach:
Leave the public interface unchanged (the same public methods with the same arguments) but alter the private section, including the private methods and their method implementations. Test the modified version with a third version of the randwalk() function, which should be left unchanged other than using the new version of the Vector class, because the public interface of the Vector class is unchanged.
Specific approach:
You will find class definitions here that you built in the Topic A Exploration Exercises.
Create a third version of the Vector class, Vector3.
Create a new version of the randwalk() function, randwalk3(), copying the function definition you find in the Topic A Exploration Three Exercise 1 file.
Modify the declaration for Vector3 to remove the polar coordinate data members, modify the prototypes of the private methods, and change the inline definitions of the inspectors for the now-deleted polar coordinate values.
The public inspectors for polar coordinate values must now invoke the revised facilitators to get the values they compute from x-y coordinate values. These were coded as inline definitions, and can stay that way – they will still have just one statement each.
Modify the definitions for Vector3 to update the private methods.
The private methods that were originally mutators for the polar coordinate data members will need to become facilitators that compute the polar coordinate equivalents of the x-y coordinates that are stored in the class. They should be constant functions that do not modify data member values, and return double values. The existing method definitions do the correct computations, but will need to return their results rather than setting the now-deleted polar coordinate data members.
The private methods that are mutators for the x-y coordinate data members can no longer read from the polar coordinate data members, but must receive polar coordinate values as method parameters. The mutator definitions do the correct computations, and will just need to be modified to work with their new input parameters.
While no public interface changes should be made, three of the public methods will need definition changes: the two constructors and the reset() method.
There are no more polar coordinate data members to set in any of the three.
If the input parameters are provided in polar coordinate form, they still need to be converted to x-y coordinate equivalent values before being stored in the data members. All the necessary pieces are there in the existing code, needing just slight modifications to create local variables and to pass those to the mutator functions.
Modify the randwalk3() function to declare variables of the Vector3 class. This is the only modification needed.
Add a call to randwalk3() to the Homework Exercise code file. The first two versions can still be tested through the Topic A project.
both are considered 1 assaignment.

 

"Is this question part of your assignment? We Can Help!"

Nursing Coursework