1 #include <iostream> 2 3 using std::cout; 4 using std::endl; 5 6 // 类A的定义 7 class A { 8 public: 9 A(int x0, int y0); 10 void display() const; 11 12 private: 13 int x, y; 14 }; 15 16 A::A(int x0, int y0): x{x0}, y{y0} { 17 } 18 19 void A::display() const { 20 cout << x << ", " << y << endl; 21 } 22 23 // 类B的定义 24 class B { 25 public: 26 B(double x0, double y0); 27 void display() const; 28 29 private: 30 double x, y; 31 }; 32 33 B::B(double x0, double y0): x{x0}, y{y0} { 34 } 35 36 void B::display() const { 37 cout << x << ", " << y << endl; 38 } 39 40 void test() { 41 cout << "测试类A: " << endl; 42 A a(3, 4); 43 a.display(); 44 45 cout << "\n测试类B: " << endl; 46 B b(3.2, 5.6); 47 b.display(); 48 } 49 50 int main() { 51 test(); 52 } 53 54 55 56 #include <iostream> 57 #include <string> 58 59 using std::cout; 60 using std::endl; 61 using std::string; 62 63 // 定义类模板 64 template<typename T> 65 class X{ 66 public: 67 X(T x0, T y0); 68 void display(); 69 70 private: 71 T x, y; 72 }; 73 74 template<typename T> 75 X<T>::X(T x0, T y0): x{x0}, y{y0} { 76 } 77 78 template<typename T> 79 void X<T>::display() { 80 cout << x << ", " << y << endl; 81 } 82 83 84 void test() { 85 cout << "测试1: 类模板X中的抽象类型T用int实例化" << endl; 86 X<int> x1(3, 4); 87 x1.display(); 88 89 cout << endl; 90 91 cout << "测试2: 类模板X中的抽象类型T用double实例化" << endl; 92 X<double> x2(3.2, 5.6); 93 x2.display(); 94 95 cout << endl; 96 97 cout << "测试3: 类模板X中的抽象类型T用string实例化" << endl; 98 X<string> x3("hello", "oop"); 99 x3.display(); 100 } 101 102 int main() { 103 test(); 104 }


1 #include <iostream> 2 #include <vector> 3 #include <string> 4 #include <algorithm> 5 #include <numeric> 6 #include <iomanip> 7 8 using std::vector; 9 using std::string; 10 using std::cin; 11 using std::cout; 12 using std::endl; 13 14 class GradeCalc: public vector<int> { 15 public: 16 GradeCalc(const string &cname, int size); 17 void input(); // 录入成绩 18 void output() const; // 输出成绩 19 void sort(bool ascending = false); // 排序 (默认降序) 20 int min() const; // 返回最低分 21 int max() const; // 返回最高分 22 float average() const; // 返回平均分 23 void info(); // 输出课程成绩信息 24 25 private: 26 void compute(); // 成绩统计 27 28 private: 29 string course_name; // 课程名 30 int n; // 课程人数 31 vector<int> counts = vector<int>(5, 0); // 保存各分数段人数([0, 60), [60, 70), [70, 80), [80, 90), [90, 100] 32 vector<double> rates = vector<double>(5, 0); // 保存各分数段比例 33 }; 34 35 GradeCalc::GradeCalc(const string &cname, int size): course_name{cname}, n{size} {} 36 37 void GradeCalc::input() { 38 int grade; 39 40 for(int i = 0; i < n; ++i) { 41 cin >> grade; 42 this->push_back(grade); 43 } 44 } 45 46 void GradeCalc::output() const { 47 for(auto ptr = this->begin(); ptr != this->end(); ++ptr) 48 cout << *ptr << " "; 49 cout << endl; 50 } 51 52 void GradeCalc::sort(bool ascending) { 53 if(ascending) 54 std::sort(this->begin(), this->end()); 55 else 56 std::sort(this->begin(), this->end(), std::greater<int>()); 57 } 58 59 int GradeCalc::min() const { 60 return *std::min_element(this->begin(), this->end()); 61 } 62 63 int GradeCalc::max() const { 64 return *std::max_element(this->begin(), this->end()); 65 } 66 67 float GradeCalc::average() const { 68 return std::accumulate(this->begin(), this->end(), 0) * 1.0 / n; 69 } 70 71 void GradeCalc::compute() { 72 for(int grade: *this) { 73 if(grade < 60) 74 counts.at(0)++; 75 else if(grade >= 60 && grade < 70) 76 counts.at(1)++; 77 else if(grade >= 70 && grade < 80) 78 counts.at(2)++; 79 else if(grade >= 80 && grade < 90) 80 counts.at(3)++; 81 else if(grade >= 90) 82 counts.at(4)++; 83 } 84 85 for(int i = 0; i < rates.size(); ++i) 86 rates.at(i) = counts.at(i) * 1.0 / n; 87 } 88 89 void GradeCalc::info() { 90 cout << "课程名称:\t" << course_name << endl; 91 cout << "排序后成绩: \t"; 92 sort(); output(); 93 cout << "最高分:\t" << max() << endl; 94 cout << "最低分:\t" << min() << endl; 95 cout << "平均分:\t" << std::fixed << std::setprecision(2) << average() << endl; 96 97 compute(); // 统计各分数段人数、比例 98 99 vector<string> tmp{"[0, 60) ", "[60, 70)", "[70, 80)","[80, 90)", "[90, 100]"}; 100 for(int i = tmp.size()-1; i >= 0; --i) 101 cout << tmp[i] << "\t: " << counts[i] << "人\t" 102 << std::fixed << std::setprecision(2) << rates[i]*100 << "%" << endl; 103 } 104 105 106 #include "GradeCalc.hpp" 107 #include <iomanip> 108 109 void test() { 110 int n; 111 cout << "输入班级人数: "; 112 cin >> n; 113 114 GradeCalc c1("OOP", n); 115 116 cout << "录入成绩: " << endl;; 117 c1.input(); 118 cout << "输出成绩: " << endl; 119 c1.output(); 120 121 cout << string(20, '*') + "课程成绩信息" + string(20, '*') << endl; 122 c1.info(); 123 } 124 125 int main() { 126 test(); 127 }

1 #include "GradeCalc.hpp" 2 #include <iomanip> 3 4 void test() { 5 int n; 6 cout << "输入班级人数: "; 7 cin >> n; 8 9 GradeCalc c1("OOP", n); 10 11 cout << "录入成绩: " << endl;; 12 c1.input(); 13 cout << "输出成绩: " << endl; 14 c1.output(); 15 16 cout << string(20, '*') + "课程成绩信息" + string(20, '*') << endl; 17 c1.info(); 18 } 19 20 int main() { 21 test(); 22 } 23 24 25 26 27 #include <iostream> 28 #include <vector> 29 #include <string> 30 #include <algorithm> 31 #include <numeric> 32 #include <iomanip> 33 34 using std::vector; 35 using std::string; 36 using std::cin; 37 using std::cout; 38 using std::endl; 39 40 class GradeCalc { 41 public: 42 GradeCalc(const string &cname, int size); 43 void input(); // 录入成绩 44 void output() const; // 输出成绩 45 void sort(bool ascending = false); // 排序 (默认降序) 46 int min() const; // 返回最低分 47 int max() const; // 返回最高分 48 float average() const; // 返回平均分 49 void info(); // 输出课程成绩信息 50 51 private: 52 void compute(); // 成绩统计 53 54 private: 55 string course_name; // 课程名 56 int n; // 课程人数 57 vector<int> grades; // 课程成绩 58 vector<int> counts = vector<int>(5, 0); // 保存各分数段人数([0, 60), [60, 70), [70, 80), [80, 90), [90, 100] 59 vector<double> rates = vector<double>(5, 0); // 保存各分数段比例 60 }; 61 62 GradeCalc::GradeCalc(const string &cname, int size): course_name{cname}, n{size} {} 63 64 void GradeCalc::input() { 65 int grade; 66 67 for(int i = 0; i < n; ++i) { 68 cin >> grade; 69 grades.push_back(grade); 70 } 71 } 72 73 void GradeCalc::output() const { 74 for(int grade: grades) 75 cout << grade << " "; 76 cout << endl; 77 } 78 79 void GradeCalc::sort(bool ascending) { 80 if(ascending) 81 std::sort(grades.begin(), grades.end()); 82 else 83 std::sort(grades.begin(), grades.end(), std::greater<int>()); 84 85 } 86 87 int GradeCalc::min() const { 88 return *std::min_element(grades.begin(), grades.end()); 89 } 90 91 int GradeCalc::max() const { 92 return *std::max_element(grades.begin(), grades.end()); 93 } 94 95 float GradeCalc::average() const { 96 return std::accumulate(grades.begin(), grades.end(), 0) * 1.0 / n; 97 } 98 99 void GradeCalc::compute() { 100 for(int grade: grades) { 101 if(grade < 60) 102 counts.at(0)++; 103 else if(grade >= 60 && grade < 70) 104 counts.at(1)++; 105 else if(grade >= 70 && grade < 80) 106 counts.at(2)++; 107 else if(grade >= 80 && grade < 90) 108 counts.at(3)++; 109 else if(grade >= 90) 110 counts.at(4)++; 111 } 112 113 for(int i = 0; i < rates.size(); ++i) 114 rates.at(i) = counts.at(i) *1.0 / n; 115 } 116 117 void GradeCalc::info() { 118 cout << "课程名称:\t" << course_name << endl; 119 cout << "排序后成绩: \t"; 120 sort(); output(); 121 cout << "最高分:\t" << max() << endl; 122 cout << "最低分:\t" << min() << endl; 123 cout << "平均分:\t" << std::fixed << std::setprecision(2) << average() << endl; 124 125 compute(); // 统计各分数段人数、比例 126 127 vector<string> tmp{"[0, 60) ", "[60, 70)", "[70, 80)","[80, 90)", "[90, 100]"}; 128 for(int i = tmp.size()-1; i >= 0; --i) 129 cout << tmp[i] << "\t: " << counts[i] << "人\t" 130 << std::fixed << std::setprecision(2) << rates[i]*100 << "%" << endl; 131 }

1 #include <iostream> 2 #include <string> 3 #include <limits> 4 5 using namespace std; 6 7 void test1() { 8 string s1, s2; 9 cin >> s1 >> s2; // cin: 从输入流读取字符串, 碰到空白符(空格/回车/Tab)即结束 10 cout << "s1: " << s1 << endl; 11 cout << "s2: " << s2 << endl; 12 } 13 14 void test2() { 15 string s1, s2; 16 getline(cin, s1); // getline(): 从输入流中提取字符串,直到遇到换行符 17 getline(cin, s2); 18 cout << "s1: " << s1 << endl; 19 cout << "s2: " << s2 << endl; 20 } 21 22 void test3() { 23 string s1, s2; 24 getline(cin, s1, ' '); //从输入流中提取字符串,直到遇到指定分隔符 25 getline(cin, s2); 26 cout << "s1: " << s1 << endl; 27 cout << "s2: " << s2 << endl; 28 } 29 30 int main() { 31 cout << "测试1: 使用标准输入流对象cin输入字符串" << endl; 32 test1(); 33 cout << endl; 34 35 cin.ignore(numeric_limits<streamsize>::max(), '\n'); 36 37 cout << "测试2: 使用函数getline()输入字符串" << endl; 38 test2(); 39 cout << endl; 40 41 cout << "测试3: 使用函数getline()输入字符串, 指定字符串分隔符" << endl; 42 test3(); 43 }
1 #include <iostream> 2 #include <string> 3 #include <vector> 4 #include <limits> 5 6 using namespace std; 7 8 void output(const vector<string> &v) { 9 for(auto &s: v) 10 cout << s << endl; 11 } 12 13 void test() { 14 int n; 15 while(cout << "Enter n: ", cin >> n) { 16 vector<string> v1; 17 18 for(int i = 0; i < n; ++i) { 19 string s; 20 cin >> s; 21 v1.push_back(s); 22 } 23 24 cout << "output v1: " << endl; 25 output(v1); 26 cout << endl; 27 } 28 } 29 30 int main() { 31 cout << "测试: 使用cin多组输入字符串" << endl; 32 test(); 33 }
1 #include <iostream> 2 #include <string> 3 #include <vector> 4 #include <limits> 5 6 using namespace std; 7 8 void output(const vector<string> &v) { 9 for(auto &s: v) 10 cout << s << endl; 11 } 12 13 void test() { 14 int n; 15 while(cout << "Enter n: ", cin >> n) { 16 cin.ignore(numeric_limits<streamsize>::max(), '\n'); 17 18 vector<string> v2; 19 20 for(int i = 0; i < n; ++i) { 21 string s; 22 getline(cin, s); 23 v2.push_back(s); 24 } 25 cout << "output v2: " << endl; 26 output(v2); 27 cout << endl; 28 } 29 } 30 31 int main() { 32 cout << "测试: 使用函数getline()多组输入字符串" << endl; 33 test(); 34 }



cin.ignore用于跳过前面读取时的换行符号“\n”,否则后面getline()执行操作时会误认为输入已结束。
1 #ifndef GRM_HPP 2 #define GRM_HPP 3 4 template <typename T> 5 class GameResourceManager { 6 private: 7 T resource; 8 9 public: 10 GameResourceManager(T initialResource) : resource(initialResource) {} 11 12 T get() const { 13 return resource; 14 } 15 16 void update(T amount) { 17 resource += amount; 18 if (resource < 0) { 19 resource = 0; 20 } 21 } 22 }; 23 24 #endif 25 26 27 28 #include "grm.hpp" 29 #include <iostream> 30 31 using std::cout; 32 using std::endl; 33 34 void test1() { 35 GameResourceManager<float> HP_manager(99.99); 36 cout << "当前生命值: " << HP_manager.get() << endl; 37 HP_manager.update(9.99); 38 cout << "增加9.99生命值后, 当前生命值: " << HP_manager.get() << endl; 39 HP_manager.update(-999.99); 40 cout <<"减少999.99生命值后, 当前生命值: " << HP_manager.get() << endl; 41 } 42 43 void test2() { 44 GameResourceManager<int> Gold_manager(100); 45 cout << "当前金币数量: " << Gold_manager.get() << endl; 46 Gold_manager.update(50); 47 cout << "增加50个金币后, 当前金币数量: " << Gold_manager.get() << endl; 48 Gold_manager.update(-99); 49 cout <<"减少99个金币后, 当前金币数量: " << Gold_manager.get() << endl; 50 } 51 52 53 int main() { 54 cout << "测试1: 用float类型对类模板GameResourceManager实例化" << endl; 55 test1(); 56 cout << endl; 57 58 cout << "测试2: 用int类型对类模板GameResourceManager实例化" << endl; 59 test2(); 60 }

1 #include <iostream> 2 #include <string> 3 using namespace std; 4 5 class Info { 6 private: 7 string nickname; 8 string contact; 9 string city; 10 int num; 11 public: 12 void input() { 13 cout << "请输入昵称: "; 14 cin >> nickname; 15 cout << "请输入联系方式(邮箱/手机): "; 16 cin >> contact; 17 cout << "请输入所在城市: "; 18 cin >> city; 19 cout << "请输入预定参加人数: "; 20 cin >> num; 21 } 22 23 24 void display() const { 25 cout << "昵称: " << nickname << endl; 26 cout << "联系方式: " << contact << endl; 27 cout << "所在城市: " << city << endl; 28 cout << "预定人数: " << num << endl; 29 } 30 31 void update() { 32 cout << "请输入更新的预定人数: "; 33 cin >> num; 34 } 35 36 int getNum() const { return num; } 37 38 void setNum(int newNum) { num = newNum; } 39 40 string getNickname() const { return nickname; } 41 }; 42 43 44 #include "info.hpp" 45 #include <vector> 46 #include <algorithm> 47 using std::vector; 48 49 int main() { 50 const int capacity = 100; 51 vector<Info> audience_list; 52 int total_audience = 0; 53 while (true) { 54 cout << "请录入观众信息(按Ctrl+Z退出): " << endl; 55 Info temp; 56 temp.input(); 57 58 auto it = std::find_if(audience_list.begin(), audience_list.end(), [&](const Info& info) { 59 return info.getNickname() == temp.getNickname(); 60 }); 61 62 if (it != audience_list.end()) { 63 64 total_audience -= it->getNum(); 65 it->update(); 66 total_audience += it->getNum(); 67 } else { 68 69 if (total_audience + temp.getNum() > capacity) { 70 cout << "预定人数超出最大容量,仅允许预定 " 71 << (capacity - total_audience) << " 人。" << endl; 72 temp.setNum(capacity - total_audience); 73 } 74 audience_list.push_back(temp); 75 total_audience += temp.getNum(); 76 } 77 78 if (total_audience >= capacity) { 79 cout << "人数已满,无法继续录入!" << endl; 80 break; 81 } 82 } 83 84 cout << "\n已预约的观众信息如下:" << endl; 85 for (const auto& info : audience_list) { 86 info.display(); 87 cout << "------------------------" << endl; 88 } 89 90 return 0; 91 }

1 #ifndef __DATE_H__ 2 #define __DATE_H__ 3 class Date{ 4 private: 5 int year; 6 int month; 7 int day; 8 int totalDays; 9 public: 10 Date(int year,int month,int day); 11 int getYear() const {return year;} 12 int getMonth() const {return month;} 13 int getDay() const {return day;} 14 int getMaxDay() const; 15 bool isLeapYear() const { 16 return year%4==0 && year%100 !=0 ||year%400==0; 17 } 18 void show() const; 19 20 int distance(const Date& date) const { 21 return totalDays-date.totalDays; 22 } 23 }; 24 #endif //__DATE_H__ 25 26 #include "date.h" 27 #include <iostream> 28 #include <cstdlib> 29 using namespace std; 30 namespace { 31 const int DAYS_BEFORE_MONTH[]={0,31,59,90,120,151,181,212,243,273,304,334,365}; 32 } 33 Date::Date(int year,int month,int day):year(year),month(month),day(day) { 34 if(day<=0||day>getMaxDay()) { 35 cout<<"Invalid date:"; 36 show(); 37 cout<<endl; 38 exit(1); 39 } 40 int years=year-1; 41 totalDays = years *365+years/4-years/100+years/400+DAYS_BEFORE_MONTH[month-1]+day; 42 if(isLeapYear()&&month>2) totalDays++; 43 } 44 45 int Date::getMaxDay() const { 46 if(isLeapYear()&&month==2) 47 return 29; 48 else 49 return DAYS_BEFORE_MONTH[month]-DAYS_BEFORE_MONTH[month-1]; 50 } 51 52 void Date::show() const { 53 cout<<getYear()<<"-"<<getMonth()<<"-"<<getDay(); 54 } 55 56 #pragma once 57 #ifndef ACCOUNT H 58 #define ACCOUNT H 59 #include"date.h" 60 #include"accumulator.h" 61 #include<string> 62 class Account { 63 private: 64 std::string id; 65 double balance; 66 static double total; 67 protected: 68 Account(const Date& date, const std::string& id); 69 void record(const Date& date, double amount, const std::string& desc); 70 void error(const std::string& msg)const; 71 public: 72 const std::string& getId()const { return id; } 73 double getBalance()const { return balance; } 74 static double getTotal() { return total; } 75 76 void show()const; 77 }; 78 class SavingsAccount :public Account { 79 private: 80 Accumulator acc; 81 double rate; 82 public: 83 SavingsAccount(const Date& date, const std::string& id, double rate); 84 double getRate()const { return rate; } 85 86 void deposit(const Date& date, double amount, const std::string& desc); 87 void withdraw(const Date& date, double amount, const std::string& desc); 88 void settle(const Date& date); 89 }; 90 class CreditAccount :public Account { 91 private: 92 Accumulator acc; 93 double credit; 94 double rate; 95 double fee; 96 double getDebt()const { 97 double balance = getBalance(); 98 return (balance < 0 ? balance : 0); 99 } 100 public: 101 CreditAccount(const Date& date, const std::string& id, double credit, double rate, double fee); 102 double getCredit()const { return credit; } 103 double getRate()const { return rate;} 104 double getAvailableCredit()const { 105 if (getBalance() < 0) 106 return credit + getBalance(); 107 else 108 return credit; 109 } 110 void deposit(const Date& date, double amount, const std::string& desc); 111 void withdraw(const Date& date, double amount, const std::string& desc); 112 void settle(const Date& date); 113 void show()const; 114 }; 115 #endif//ACCOUNT H 116 117 #pragma once 118 #ifndef ACCUMULATOR H 119 #define ACCUMULATOR H 120 #include"date.h" 121 class Accumulator { 122 private: 123 Date lastDate; 124 double value; 125 double sum; 126 public: 127 Accumulator(const Date& date, double value) :lastDate(date), value(value), sum{ 0 } { 128 } 129 130 double getSum(const Date& date)const { 131 return sum + value * date.distance(lastDate); 132 } 133 134 void change(const Date& date, double value) { 135 sum = getSum(date); 136 lastDate = date; this->value = value; 137 } 138 139 void reset(const Date& date, double value) { 140 lastDate = date; this->value = value; sum = 0; 141 } 142 }; 143 #endif//ACCUMULATOR H 144 145 #include"account.h" 146 #include<cmath> 147 #include<iostream> 148 using namespace std; 149 double Account::total = 0; 150 151 Account::Account(const Date& date, const string& id) :id{ id }, balance{ 0 } { 152 date.show(); cout << "\t#" << id << "created" << endl; 153 } 154 155 156 void Account::record(const Date& date, double amount, const string& desc) { 157 amount = floor(amount * 100 + 0.5) / 100; 158 balance += amount; 159 total += amount; 160 date.show(); 161 cout << "\t#" << id << "\t" << amount << "\t" << balance << "\t" << desc << endl; 162 } 163 164 void Account::show()const { cout << id << "\tBalance:" << balance; } 165 void Account::error(const string& msg)const { 166 cout << "Error(#" << id << "):" << msg << endl; 167 } 168 169 SavingsAccount::SavingsAccount(const Date& date, const string& id, double rate) :Account(date, id), rate(rate), acc(date, 0) {} 170 171 void SavingsAccount::deposit(const Date& date, double amount, const string& desc) { 172 record(date, amount, desc); 173 acc.change(date, getBalance()); 174 } 175 176 void SavingsAccount::withdraw(const Date& date, double amount, const string& desc) { 177 if (amount > getBalance()) { 178 error("not enough money"); 179 } 180 else { 181 record(date, -amount, desc); 182 acc.change(date, getBalance()); 183 } 184 } 185 186 void SavingsAccount::settle(const Date& date) { 187 double interest = acc.getSum(date) * rate / date.distance(Date(date.getYear() - 1, 1, 1)); 188 if (interest != 0)record(date, interest, "interest"); 189 acc.reset(date, getBalance()); 190 } 191 192 CreditAccount::CreditAccount(const Date& date, const string& id, double credit, double rate, double fee) :Account(date, id), credit(credit), rate(rate), fee(fee), acc(date, 0) {} 193 194 void CreditAccount::deposit(const Date& date, double amount, const string& desc) { 195 record(date, amount, desc); 196 acc.change(date, getDebt()); 197 } 198 199 void CreditAccount::withdraw(const Date& date, double amount, const string& desc) { 200 if (amount - getBalance() > credit) { 201 error("not enough credit"); 202 } 203 else { 204 record(date, -amount, desc); 205 acc.change(date, getDebt()); 206 } 207 } 208 209 void CreditAccount::settle(const Date& date) { 210 double interest = acc.getSum(date) * rate; 211 if (interest != 0)record(date, interest, "interest"); 212 if (date.getMonth() == 1) 213 record(date, -fee, "annual fee"); 214 acc.reset(date, getDebt()); 215 } 216 217 void CreditAccount::show()const { 218 Account::show(); 219 cout << "\tAvailable credit:" << getAvailableCredit(); 220 } 221 222 #include"account.h" 223 #include<iostream> 224 225 using namespace std; 226 227 int main() { 228 Date date(2008, 11, 1); 229 SavingsAccount sa1(date, "S3755217", 0.015); 230 SavingsAccount sa2(date, "02342342", 0.015); 231 CreditAccount ca(date, "C5392394", 10000, 0.0005, 50); 232 233 sa1.deposit(Date(2008, 11, 5), 5000, "salary"); 234 ca.withdraw(Date(2008, 11, 15), 2000, "buy a cell"); 235 sa2.deposit(Date(2008, 11, 25), 10000, "sell stock 0323"); 236 237 ca.settle(Date(2008, 12, 1)); 238 239 ca.deposit(Date(2008, 12, 1), 2016, "repay the credit"); 240 sa1.deposit(Date(2008, 12, 5), 5500, "salary"); 241 242 sa1.settle(Date(2009, 1, 1)); 243 sa2.settle(Date(2009, 1, 1)); 244 ca.settle(Date(2009, 1, 1)); 245 246 cout << endl; 247 sa1.show(); cout << endl; 248 sa2.show(); cout << endl; 249 ca.show(); cout << endl; 250 cout << "Total:" << Account::getTotal() << endl; 251 return 0; 252 }
