#include #include "Vector_3d.hpp" // Compile this file together with Vector_3d.cpp. // // This file contains a main() function. A C++ program can // have only one main() function. If your project already // contains a main.cpp file, either: // // 1. remove main.cpp from the project or build, or // // 2. temporarily rename its main() function to old_main(). // // The second option allows the original demonstration // program to remain in the project while this program is // being compiled and run. int main() { // The member variables of Vector_3d are public. Vector_3d u{ 3.2, -4.5, 2.1 }; std::cout << "Initially:" << std::endl; std::cout << "u = " << u << std::endl; // Consequently, the user can access the member // variables directly. std::cout << std::endl << "The individual components are:" << std::endl; std::cout << "u.x_ = " << u.x_ << std::endl; std::cout << "u.y_ = " << u.y_ << std::endl; std::cout << "u.z_ = " << u.z_ << std::endl; // The user can also modify the member variables directly. u.x_ = 10.0; u.y_ = 20.0; u.z_ = 30.0; std::cout << std::endl << "After modifying the member variables:" << std::endl; std::cout << "u = " << u << std::endl; // In this particular class, allowing direct access to // the member variables does not cause an obvious problem. // // Any three double-precision floating-point values form // a valid 3-dimensional vector. There is no relationship // between x_, y_, and z_ that must be maintained. // // This will not be true for all classes. In particular, // our Rational and Array classes have conditions that // their member variables must satisfy. return 0; }