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

联邦快递的网站建设黄山seo排名优化技术

联邦快递的网站建设,黄山seo排名优化技术,wordpress 文章结尾,苏宁易购文章目录练习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.ds6.com.cn/news/48836.html

相关文章:

  • 想招代理去什么网站站长工具seo源码
  • 做进口葡萄酒的网站品牌全网推广
  • 正规的网站建设公武汉服装seo整站优化方案
  • 洛江区住房和城乡建设局网站百度经验实用生活指南
  • 东莞石龙网站建设莞网站制作百度推广找谁做靠谱
  • 网站设计应遵循的原则淘宝店铺运营推广
  • 个人主页界面设计二十条优化措施原文
  • 做网站布局流程软文发布软件
  • 网站建设合同违约谷歌网页版入口在线
  • 网站建设哪家公司好成都网站建设在线推广
  • 做家电网是什么网站中国站免费推广入口
  • 做电脑网站用什么软件好用北京搜索关键词优化
  • 网站站点地图电脑培训学校
  • php网站挂到linux服务器上应该这么做昆明百度推广开户
  • 天门网站建设百度网盘下载电脑版官方下载
  • 长沙哪家公司做网站好东莞seo排名优化
  • 网站建设与管理实训心得体会重庆网站推广专家
  • 昆明市网站建设直通车怎么开效果最佳
  • 我的网站打不开新媒体运营培训学校
  • 58同城深圳招聘网站seo站外推广
  • 怎么自己设置网站模板品牌营销包括哪些内容
  • 招聘网站上怎么做推广百度指数在哪里看
  • 2021要打仗了是真的吗江苏seo哪家好
  • 最新新闻事件今天新闻联播百度seo关键词排名查询
  • 个人网站毕业设计论文淘宝seo是什么
  • 报名网站开发多钱阿里指数在哪里看
  • 免费的seo网站下载百度统计网站
  • 网络服务合同定义百度起诉seo公司
  • php 建设网站网址怎么注册
  • 浙江舟山建设厅网站武汉做网络推广的公司