当前位置: 首页 > news >正文

支付网站建设费进什么科目扬州seo优化

支付网站建设费进什么科目,扬州seo优化,app 与网站,网页设计代码解释文章目录练习3.1练习3.2一次读入一行一次读入一个词练习3.3练习3.4大的字符串长度大的字符串练习3.5未隔开的隔开的练习3.6练习3.7练习3.8练习3.9练习3.10练习3.1 使用恰当的using 声明重做 1.4.1节和2.6.2节的练习。 // 1.4.1 #include <iostream>using std::cin; using…

文章目录

      • 练习3.1
      • 练习3.2
        • 一次读入一行
        • 一次读入一个词
      • 练习3.3
      • 练习3.4
        • 大的字符串
        • 长度大的字符串
      • 练习3.5
        • 未隔开的
        • 隔开的
      • 练习3.6
      • 练习3.7
      • 练习3.8
      • 练习3.9
      • 练习3.10

练习3.1

使用恰当的using 声明重做 1.4.1节和2.6.2节的练习。

// 1.4.1
#include <iostream>using std::cin;
using std::cout;
using std::endl;int main()
{int sum = 0;for (int val = 1; val <= 10; ++val) sum += val;cout << "Sum of 1 to 10 inclusive is " << sum << endl;return 0;
}// 2.6.2
#include <iostream>
#include <string>
#include "exercise2_42.h"using std::cin;
using std::cout;
using std::endl;
using std::cerr;int main()
{Sales_data data1, data2;double price = 0;  cin >> data1.bookNo >> data1.units_sold >> price;data1.revenue = data1.units_sold * price;cin >> data2.bookNo >> data2.units_sold >> price;data2.revenue = data2.units_sold * price;if (data1.bookNo == data2.bookNo){unsigned totalCnt = data1.units_sold + data2.units_sold;double totalRevenue = data1.revenue + data2.revenue;cout << data1.bookNo << " " << totalCnt<< " " << totalRevenue << " ";if (totalCnt != 0)cout << totalRevenue / totalCnt << endl;elsecout << "(no sales)" << endl;return 0;  }else{  cerr << "Data must refer to the same ISBN" << endl;return -1; }
}

练习3.2

编写一段程序从标准输入中一次读入一行,然后修改该程序使其一次读入一个词。

一次读入一行

#include <iostream>
#include <string>using std::string;
using std::cin;
using std::cout;
using std::endl;
using std::getline;int main()
{string s;while (getline(cin,s)){cout << s << endl;}return 0;
}

一次读入一个词

#include <iostream>
#include <string>using std::string;
using std::cin;
using std::cout;
using std::endl;int main()
{string s;while (cin >> s){cout << s << endl;}return 0;
}

练习3.3

请说明string类的输入运算符和getline函数分别是如何处理空白字符的。

  • 类似 is >> s 的读取,string对象会忽略开头的空白并从第一个真正的字符开始,直到遇见下一空白为止。
  • 类似 getline(is, s) 的读取,string对象会从输入流中读取字符,直到遇见换行符为止。

练习3.4

编写一段程序读取两个字符串,比较其是否相等并输出结果。如果不相等,输出比较大的那个字符串。改写上述程序,比较输入的两个字符串是否等长,如果不等长,输出长度较大的那个字符串。

大的字符串

#include <iostream>
#include <string>
using std::string;
using std::cin;
using std::cout;
using std::endl;int main()
{string str1, str2;while (cin >> str1 >> str2){if (str1 == str2)cout << "The two strings are equal." << endl;elsecout << "The larger string is " << ((str1 > str2) ? str1 : str2);}return 0;
}

长度大的字符串

#include <iostream>
#include <string>
using std::string;
using std::cin;
using std::cout;
using std::endl;int main()
{string str1, str2;while (cin >> str1 >> str2){if (str1.size() == str2.size())cout << "The two strings have the same length." << endl;elsecout << "The longer string is " << ((str1.size() > str2.size()) ? str1 : str2) << endl;}return 0;

练习3.5

编写一段程序从标准输入中读入多个字符串并将他们连接起来,输出连接成的大字符串。然后修改上述程序,用空格把输入的多个字符串分割开来。

未隔开的

#include <iostream>
#include <string>using std::string;
using std::cin;
using std::cout;
using std::endl;int main()
{string result, s;while (cin >> s){result += s;}cout << result << endl;return 0;
}

隔开的

#include <iostream>
#include <string>using std::string;
using std::cin;
using std::cout;
using std::endl;int main()
{string result, s;while (cin >> s){result += s + " ";}cout << result << endl;return 0;
}

练习3.6

编写一段程序,使用范围for语句将字符串内所有字符用X代替。

#include <iostream>
#include <string>
#include <cctype>using std::string;
using std::cin;
using std::cout;
using std::endl;int main()
{string s = "this is a string";for (auto &x : s){x = 'X';}cout << s << endl;return 0;
}

练习3.7

就上一题完成的程序而言,如果将循环控制的变量设置为char将发生什么?先估计一下结果,然后实际编程进行验证。

如果设置为char,那么原来的字符串不会发生改变。

#include <iostream>
#include <string>
#include <cctype>using std::string;
using std::cin;
using std::cout;
using std::endl;int main()
{string s = "this is a string";for (char x : s){x = 'X';}cout << s << endl;return 0;
}

练习3.8

分别用while循环和传统for循环重写第一题的程序,你觉得哪种形式更好呢?为什么?

范围for语句更好,不直接操作索引,更简洁。

#include <iostream>
#include <string>
#include <cctype>using std::string;
using std::cin;
using std::cout;
using std::endl;int main()
{string s = "this is a string";decltype(s.size()) i = 0;while (i != s.size()){s[i] = 'X';++i;}cout << s << endl;for (i = 0; i != s.size(); ++i){s[i] = 'Y';}cout << s << endl;return 0;
}

练习3.9

下面的程序有何作用?它合法吗?如果不合法?为什么?

string s;
cout << s[0] << endl;

不合法。使用下标访问空字符串是非法的行为。

练习3.10

编写一段程序,读入一个包含标点符号的字符串,将标点符号去除后输出字符串剩余的部分。

#include <iostream>
#include <string>
#include <cctype>using std::string;
using std::cin;
using std::cout;
using std::endl;int main()
{string s = "this, is. a :string!";string result;for (auto x : s){if (!ispunct(x)){result += x;}}cout << result << endl;return 0;
}
http://www.tj-hxxt.cn/news/13864.html

相关文章:

  • dede 手机网站插件媒体:北京不再公布疫情数据
  • 个人怎么注册商贸公司seo网站管理
  • 做网站看网页效果软文营销的案例
  • 合同下载 公司网站百度近日收录查询
  • 天峨县建设局网站宁波seo网页怎么优化
  • 网站的建设成本优化搜狗排名
  • 横峰网站建设网站死链检测工具
  • 作文网站投稿做小程序公司哪家好
  • 企业网站建设的公司营销策略国内外文献综述
  • 网站建设考试多选题我想接app注册推广单
  • 建自己的网站做网站排名服务热线
  • 网站建设平台协议书seo研究中心教程
  • 品牌建设包括做网站seo优化
  • 网站建设的会计分录腾讯广告投放平台
  • 做bt搜索网站百度官方版
  • 购物平台网站建设流程市场调研报告怎么做
  • 新闻热点事件2020 最新优化用户体验
  • 赣州那里有做网站的公司优化大师官网
  • 北京高端商场seo什么意思
  • 石景山周边网站建设seo查询软件
  • 哪里建设网站不会被封应用宝aso优化
  • seo关键词排名优化要多少钱软媒win7优化大师
  • Wordpress 删除nginx福州seo结算
  • 手机应用商店下载安装北京推广优化公司
  • 做网站 数据库北京网站优化站优化
  • 九江专业网站建设定制百度文库首页官网
  • 山西省网站备案要多久爱站工具包
  • 电子商务网站开发计划书企业培训体系搭建
  • 网站首页怎么做全屏swfseo推广具体做什么
  • 个人注册域名网站怎么做上海关键词优化报价