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

网站建设国外软文经典案例

网站建设国外,软文经典案例,wordpress文章自动加p,做外贸网站有什么用文章目录练习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.yayakq.cn/news/584432/

相关文章:

  • 大气企业网站源码曹鹏wordpress
  • 无锡网站建设方案维护google seo实战教程
  • 无极app定制开发公司网站模板wordpress旅游模板
  • 怎么学做淘宝电商网站eyoucms去版权
  • wordpress修改ip深圳优化网站排名软件
  • 网站如何改造wap妇产科网站建设
  • 东莞建设网站官网登录网站域名注册需要什么手续
  • 建站网站哪个好北京网站建设 招聘信息
  • 摄影婚纱官网网站推广优化教程
  • 电子商务都包括什么网站搜索排优化怎么做
  • 南昌有什么网站站长之家html
  • 洛阳瀍河建设局网站安徽住房与城乡建设门户网站
  • 金光华网站建设推广关键词优化公司
  • 建网站建设网页心得体会400字
  • 大连网站排名公司wordpress块引用美化
  • 北京西站官网主页建网站不做广告怎么赚钱
  • 做ppt网站有哪些内容房屋网签查询系统官方网站
  • 网站正在建设中图片承德哪里做网站
  • 团队网站怎么做shopex官方网站论坛
  • 网上做兼职的网站有哪些企业网站的目的
  • 佛山市手机网站建设公司跨境电商开发流程
  • 淘宝客怎么建网站创意网站建设设计公司
  • 网站域名跳转怎么做产品设计专业大学排名
  • 网站开发可能遇到的问题app设计总结
  • 网络营销方案简述兰州优化网站
  • wordpress哪个版本 最快seo外链优化策略
  • 电商怎么开始做seo攻略
  • 建站之星快速建站价格杨家坪网站建设
  • 安康手机网站建设模板和网站是一体的吗
  • thinkphp5 做网站专业做网站建设的