[VC++2005入门经典]第二章源代码分析_上部Ex2_10至Ex2_14
2007-08-15 14:13
423 查看
有"/n",这段用的是全局变量
//Ex2_09.cpp
//Demonstration namespace names
#include <iostream>
int value=0;
int main()
{
std::cout<<"enter an integer:";
std::cin>>value;
std::cout<<"/nYou entered "<<value<<std::endl;
return 0;
}
有"/n",这段是关于命名空间的声明的
//Ex2_10.cpp
//Declaring a namespace 声明命名空间
#include <iostream>
namespace myStuff
{
int value=0;
}
int main()
{
std::cout<<"enter an integer:";
std::cin>>myStuff::value;
std::cout<<"/nYou entered "<<myStuff::value <<std::endl;
return 0;
}
//Ex2_11.cpp
//using a using directive
#include <iostream>
namespace myStuff
{
int value=0;
}
using namespace myStuff;
int main()
{
std::cout<<"enter an integer:";
std::cin>>value;
std::cout<<"/nYou entered "<<value;
std::cout<<std::endl;
return 0;
}
// Ex2_12_CLR.cpp: 主项目文件。
#include "stdafx.h"
using namespace System;
int main(array<System::String ^> ^args)
{
int apples,oranges;
int fruit;
apples=5;oranges=6;
fruit=apples+oranges;
Console::WriteLine(L"/nOranges are not the only fruit...");//“L”的含义指后面的字符是宽字符(每个字符,包括英文占2字节)
Console::Write(L" And we have ");//Write 写在同一行,WriteLine换行。
Console::Write(fruit);
Console::Write(L" fruits in all./n");
return 0;
}
//Ex2_13.cp:main project file.
//Calculating the price of a carpet
#include "stdafx.h"
using namespace System;
int main(array<System::String ^> ^args)
...{
double carpetPriceSqYd=27.95;
double roomWidth=13.5;
double roomLength=24.75;
const int feetPerYard=3;
double roomWidthYds=roomWidth/feetPerYard;
double roomLengthYds=roomLength/feetPerYard;
double carpetPrice=roomWidthYds*roomLengthYds*carpetPriceSqYd;
Console::WriteLine(L"Room size is {0:F2} yards by {1:F2} yards",roomLengthYds,roomWidthYds);
//{0:F2}中的0表示WriteLine的第一个参数的该位置由WriteLine的第二个参数来填补。F2表示输出形式(格式)是小数,且保留2位小数
Console::WriteLine(L"Room area is {0:F2} square yards",roomLengthYds*roomWidthYds);
Console::WriteLine(L"Carpet price is ${0:F2}",carpetPrice);
return 0;
}
//Ex2_14.cpp:main project file
//Defining and using a C++/CLI enumeration.枚举
#include "stdafx.h"
using namespace System;
//Define the enumeration at global scope
enum class Suit
...{
Clubs,Diamonds,Hearts,Spades
};
int main(array<System::String ^> ^args)
...{
Suit suit =Suit::Clubs;
int value=safe_cast<int>(suit);
Console::WriteLine(L"Suit is {0} and the values is {1}",suit,value);
suit=Suit::Diamonds;
value=safe_cast<int>(suit);
Console::WriteLine(L"Suit is {0} and the values is {1}",suit,value);
suit=Suit::Hearts;
value=safe_cast<int>(suit);
Console::WriteLine(L"Suit is {0} and the values is {1}",suit,value);
suit=Suit::Spades;
value=safe_cast<int>(suit);
Console::WriteLine(L"Suit is {0} and the values is {1}",suit,value);
return 0;
}
//Ex2_09.cpp
//Demonstration namespace names
#include <iostream>
int value=0;
int main()
{
std::cout<<"enter an integer:";
std::cin>>value;
std::cout<<"/nYou entered "<<value<<std::endl;
return 0;
}
有"/n",这段是关于命名空间的声明的
//Ex2_10.cpp
//Declaring a namespace 声明命名空间
#include <iostream>
namespace myStuff
{
int value=0;
}
int main()
{
std::cout<<"enter an integer:";
std::cin>>myStuff::value;
std::cout<<"/nYou entered "<<myStuff::value <<std::endl;
return 0;
}
//Ex2_11.cpp
//using a using directive
#include <iostream>
namespace myStuff
{
int value=0;
}
using namespace myStuff;
int main()
{
std::cout<<"enter an integer:";
std::cin>>value;
std::cout<<"/nYou entered "<<value;
std::cout<<std::endl;
return 0;
}
// Ex2_12_CLR.cpp: 主项目文件。
#include "stdafx.h"
using namespace System;
int main(array<System::String ^> ^args)
{
int apples,oranges;
int fruit;
apples=5;oranges=6;
fruit=apples+oranges;
Console::WriteLine(L"/nOranges are not the only fruit...");//“L”的含义指后面的字符是宽字符(每个字符,包括英文占2字节)
Console::Write(L" And we have ");//Write 写在同一行,WriteLine换行。
Console::Write(fruit);
Console::Write(L" fruits in all./n");
return 0;
}
//Ex2_13.cp:main project file.
//Calculating the price of a carpet
#include "stdafx.h"
using namespace System;
int main(array<System::String ^> ^args)
...{
double carpetPriceSqYd=27.95;
double roomWidth=13.5;
double roomLength=24.75;
const int feetPerYard=3;
double roomWidthYds=roomWidth/feetPerYard;
double roomLengthYds=roomLength/feetPerYard;
double carpetPrice=roomWidthYds*roomLengthYds*carpetPriceSqYd;
Console::WriteLine(L"Room size is {0:F2} yards by {1:F2} yards",roomLengthYds,roomWidthYds);
//{0:F2}中的0表示WriteLine的第一个参数的该位置由WriteLine的第二个参数来填补。F2表示输出形式(格式)是小数,且保留2位小数
Console::WriteLine(L"Room area is {0:F2} square yards",roomLengthYds*roomWidthYds);
Console::WriteLine(L"Carpet price is ${0:F2}",carpetPrice);
return 0;
}
//Ex2_14.cpp:main project file
//Defining and using a C++/CLI enumeration.枚举
#include "stdafx.h"
using namespace System;
//Define the enumeration at global scope
enum class Suit
...{
Clubs,Diamonds,Hearts,Spades
};
int main(array<System::String ^> ^args)
...{
Suit suit =Suit::Clubs;
int value=safe_cast<int>(suit);
Console::WriteLine(L"Suit is {0} and the values is {1}",suit,value);
suit=Suit::Diamonds;
value=safe_cast<int>(suit);
Console::WriteLine(L"Suit is {0} and the values is {1}",suit,value);
suit=Suit::Hearts;
value=safe_cast<int>(suit);
Console::WriteLine(L"Suit is {0} and the values is {1}",suit,value);
suit=Suit::Spades;
value=safe_cast<int>(suit);
Console::WriteLine(L"Suit is {0} and the values is {1}",suit,value);
return 0;
}
相关文章推荐
- [VC++2005入门经典]第二章源代码分析_上部Ex2_01至Ex2_08
- [VC++2005入门经典]第二章练习题解答
- RTMPdump(libRTMP) 源代码分析 10: 处理各种消息(Message)
- [SharePoint2010开发入门经典]10、使用SPS2010构建面向服务的应用程序
- vc2005中DLL调用错误分析
- opencv学习(一)书本《学习Opencv》(中文版)的第二章的10个入门样例的分析
- Spring源代码分析(10)---ProxyFactoryBean(旁敲侧击的AOP时代终于来临)
- dbm数据库源代码分析(14):ndbm部分(续)
- 数据分析(入门篇)-第二章-玩转数据分析-Part5(Excel数据分析工具库-相关分析)
- 卷一 内核源代码分析 第二章 异常 2.2.3 Exynos4的中断体系 图书试读版-请勿转载
- RTMPdump(libRTMP) 源代码分析 10: 处理各种消息(Message)
- 【php学习】PHP 入门经典第二章笔记
- spring学习笔记(10)@AspectJ研磨分析[1]入门、注解基本介绍
- BlogEngine.Net架构与源代码分析系列part14:实现分析(下)——网站页面上值得参考的部分
- 算法竞赛入门经典第二章习题解答
- 算法竞赛入门经典第二版 第二章
- Quartz.NET 架构与源代码分析系列 part 1 :Quartz.NET 入门
- Tomcat7调试运行环境搭建与源代码分析入门
- {算法竞赛入门经典}第二章 如何判断整数
- 韩顺平_php从入门到精通_视频教程_第14讲_盒子模型经典应用②_作业布置_学习笔记_源代码图解_PPT文档整理