本文整理汇总了C++中Road::setLength方法的典型用法代码示例。如果您正苦于以下问题:C++ Road::setLength方法的具体用法?C++ Road::setLength怎么用?C++ Road::setLength使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Road
的用法示例。
在下文中一共展示了Road::setLength方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main()
{
//print my name and this assignments title
cout << "\n\nLab 1a,Road.h Road.cpp RoadDriver.cpp \n";
cout << "Programmer: Aysin Oruz \n";
cout << "Editor(s) used: JNotePad and Xcode \n";
cout << "Compiler(s) used: Xcode and Terminal \n";
cout << "Description: Road.cpp takes length, width of the road.";
cout << " Then program calculates the values and returns thickness of the asphalt needed.\n\n";
cout << "File: " << __FILE__ << endl;
cout << "Compiled: " << __DATE__ << " at " << __TIME__ << endl;
//create object
Road road;
//initlizating the objects
road.setLength(15.50); // set the length to a number in miles
road.setWidth(20.25); // set the width to a number in feet
road.asphalt(10.75); //set the thickness of asphalt in inches
//test setLenght function
cout.setf(ios::fixed|ios::showpoint);
cout << setprecision(2);
cout << "\nTesting setLenght\n";
cout << "Actual length: 15.50 miles \n";
cout << "Expected length is " << road.getLength() << " miles" << endl;
assert ( road.getLength() > 15.4 && road.getLength() < 15.6);
//test setWidth function
cout << "\nTesting setWidth\n";
cout << "Actual width: 20.25 feet \n";
cout << "Expected width is " << road.getWidth() << " feet" << endl;
assert ( road.getWidth() > 20.24 && road.getWidth() < 20.26);
cout.setf(ios::fixed|ios::showpoint);
cout << setprecision(2);
cout << "\nTesting asphalt" << endl;
cout << "Actual Volume is 1484628.750 cubic feet\n";
cout << "Expected volume is " << road.asphalt(10.75) << " cubic feet\n";
assert ( road.asphalt(10.75) > 1484628.749 && road.asphalt(10.75) < 1484628.751);
// object copy testing, with assignment UPON declaration
{
//test setLenght function
Road copy = road;
cout.setf(ios::fixed|ios::showpoint);
cout << setprecision(2);
cout << "\nObject copy testing, with assignment UPON declaration" << endl;
cout << "\nTesting setLenght\n";
cout << "Actual length: 15.50 miles \n";
cout << "Expected length is " << copy.getLength() << " miles" << endl;
assert ( copy.getLength() > 15.4 && copy.getLength() < 15.6);
cout << "\nTesting setWidth\n";
cout << "Actual width: 20.25 feet \n";
cout << "Expected width is " << copy.getWidth() << " feet" << endl;
assert ( copy.getWidth() > 20.24 && copy.getWidth() < 20.26);
}
// object copy testing, with assignment AFTER declaration
{
Road copy; copy = road;
cout << "\nObject copy testing, with assignment AFTER declaration" << endl;
cout << "\nTesting setLenght\n";
cout << "Actual length: 15.50 miles \n";
cout << "Expected length is " << copy.getLength() << " miles" << endl;
assert ( copy.getLength() > 15.4 && copy.getLength() < 15.6);
cout << "\nTesting setWidth\n";
cout << "Actual width: 20.25 feet \n";
cout << "Expected width is " << copy.getWidth() << " feet" << endl;
assert ( copy.getWidth() > 20.24 && copy.getWidth() < 20.26);
}
}