栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

C++ primer 第一章代码记录

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

C++ primer 第一章代码记录

//	page : 5

#include

int main()
{
	std::cout << "Enter two numbers:" << std::endl;
	int v1 = 0, v2 = 0;
	std::cin >> v1 >> v2;
	std::cout << "The sum of " << v1 << " and " 
		<< v2 << " is " << v1 + v2 << std::endl;
	system("pause");
	return 0;
}
//	page : 10

#include

int main()
{
	int sum = 0, val = 1;
	//只要Val的值小于等于10,while循环就会持续进行
	while (val <= 10)
	{
		sum += val;
		++val;
	}
	std::cout << "Sum of 1 to 10 inclusive is " << sum << std::endl;
	system("pause");
	return 0;
}
//	page : 11

#include

int main()
{
	int sum = 0;
	//从1加到10
	for (int val = 1; val <= 10; ++val)
		sum += val;
	std::cout << "Sum of 1 to 10 is " << sum << std::endl;
	system("pause");
	return 0;
}
//	page : 13

#include

int main()
{
	int sum = 0, value = 0;
	//读取数据直到遇到文件尾,计算所有读入的值的和
	while (std::cin >> value)//win系统的文件结束符尾ctrl+d
		sum += value;
	std::cout << "Sum is: " << sum << std::endl;
	system("pause");
	return 0;
}
//	page : 18

#include
#include "Sales_item.h"

int main()
{
	Sales_item book;
	
	std::cin >> book;
	std::cout << book << std::endl;
	system("pause");
	return 0;
}
//	page : 19

#include
#include "Sales_item.h"

int main()
{
	Sales_item item1,item2;
	
	std::cin >> item1 >> item2;
	std::cout << item1 + item2 << std::endl;

	system("pause");
	return 0;
}
//	page : 20

#include
#include "Sales_item.h"

int main()
{
	Sales_item item1,item2;
	
	std::cin >> item1 >> item2;
	if (item1.isbn() == item2.isbn())
	{
		std::cout << item1 + item2 << std::endl;
		system("pause");
		return 0;
	}
	else
	{
		std::cerr << "Data must refer to same ISBN"
			<< std::endl;
		system("pause");
		return -1;
	}
}
//	page : 21

#include
#include "Sales_item.h"

int main()
{
	Sales_item total;
	
	if (std::cin >> total)
	{
		Sales_item trans;
		while (std::cin >> trans)
		{
			if (total.isbn() == trans.isbn())
				total += trans;
			else
			{
				std::cout << total << std::endl;
				total = trans;
			}
		}
		std::cout << total << std::endl;
	}
	else
	{
		std::cerr << "No data?!" << std::endl;
		system("pause");
		return -1;
	}
	system("pause");
	return 0;
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1011438.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号