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

高端网站欣赏搜索百度app下载

高端网站欣赏,搜索百度app下载,wordpress安装失败无法复制文件夹,企业策划书内容9.1 单独编译 Visual Studio中新建头文件和源代码 通过解决方案资源管理器,如图所示: 分成三部分的程序(直角坐标转换为极坐标) 头文件coordin.h #ifndef __COORDIN_H__ // 如果没有被定义过 #define __COORDIN_H__struct pola…

9.1 单独编译

Visual Studio中新建头文件和源代码

通过解决方案资源管理器,如图所示:

分成三部分的程序(直角坐标转换为极坐标)

头文件coordin.h

#ifndef __COORDIN_H__ // 如果没有被定义过
#define __COORDIN_H__struct polar {double distance;double angle;
};struct rect {double x;double y;
};polar rect_to_polar(rect xypos);
void show_polar(polar dapos);#endif // 如果被定义过了(啥也不做)

源代码file1(放置main函数,调用其他函数)

#include <iostream>
#include "coordin.h" // 尖括号表明去系统目录找,双引号表明去当前目录找
using namespace std;int main(){rect rplace;polar pplace;cout << "Enter the x and y values: ";while (cin >> rplace.x >> rplace.y) {pplace = rect_to_polar(rplace);show_polar(pplace);cout << "Next two numbers (q to quit): ";}cout << "Bye!" << endl;return 0;
}

源代码file2(其他函数的定义)

#include <iostream>
#include <cmath>
#include "coordin.h"polar rect_to_polar(rect xypos) {using namespace std;polar answer;answer.distance = sqrt(xypos.x * xypos.x + xypos.y * xypos.y);answer.angle = atan2(xypos.y, xypos.x);return answer;
}void show_polar(polar dapos) {using namespace std;const double Rad_to_deg = 57.29577951;cout << "distance = " << dapos.distance;cout << ", angle = " << dapos.angle * Rad_to_deg;cout << " degrees" << endl;
}

9.2 存储持续性、作用域和链接性

全局变量和局部变量

头文件support.h

#ifndef __SUPPORT_H__
#define __SUPPORT_H__
#include <iostream>extern double warming; // 声明外部变量(不要赋值)void update(double dt);
void local(void);#endif

源代码external.cpp

#include <iostream>
#include "support.h"
using namespace std;double warming = 0.3;int main(){cout << "Global warming is " << warming << endl;update(0.1);cout << "Global warming is " << warming << endl;local();return 0;
}

源代码support.cpp

#include "support.h"
using namespace std;void update(double dt) {warming += dt;cout << "Updating global warming to " << warming << endl;
}void local(void) {double warming = 0.8; // 局部变量,只在local内部可见cout << "Local warming is " << warming << endl;// 作用域解析运算符(::),放在变量名前表示使用变量的全局版本cout << "But global warming is " << ::warming << endl;
}

static限定符用于全局变量

源代码twofile1.cpp

#include <iostream>
using namespace std;int tom = 3;
int dick = 30;
static int harry = 300; // 仅在twofile1.cpp可见
void remote_access(void);int main() {cout << "main() reports the following addresses: " << endl;cout << "&tom = " << &tom << endl;cout << "&dick = " << &dick << endl;cout << "&harry= " << &harry << endl;remote_access();return 0;
}

源代码twofile2.cpp

#include <iostream>
using namespace std;extern int tom; // 声明为外部变量(来自twofile1.cpp)
static int dick = 10; // 只在twofile2.cpp中可见
int harry = 200; // 新建一个全局变量void remote_access(void) {cout << "remote_access() reports the following addresses:" << endl;cout << "&tom = " << &tom << endl;cout << "&dick = " << &dick << endl;cout << "&harry= " << &harry << endl;
}

static限定符用于局部变量(统计字符串的字符个数)

#include <iostream>
using namespace std;const int ArSize = 10;
void strcount(const char * str);int main(){char input[ArSize];char next;cout << "Enter a line: " << endl;cin.get(input, ArSize);while (cin) {cin.get(next);// 如果输入的内容大于10个字符,则用cin.get全部消耗掉while (next != '\n')cin.get(next);strcount(input);cout << "Enter next line (empty line to quit):" << endl;cin.get(input, ArSize);}cout << "Bye!" << endl;return 0;
}void strcount(const char * str) {// 局部变量加static,无论调用多少次这个函数,该变量只会在第一次初始化static int total = 0;int count = 0;while (*str) {count++;str++;}total += count;cout << count << " characters." << endl;cout << total << " characters total." << endl;
}

定位new运算符的使用

#include <iostream>
#include <new>
using namespace std;const int BUF = 512;
const int N = 5;
char buffer[BUF];int main(){double *pd1, *pd2;int i;cout << "Calling new and placement new: " << endl;// 用常规new运算符为N个double类型开辟内存空间pd1 = new double[N];// 用定位new运算符为N个double类型开辟内存空间pd2 = new (buffer) double[N];// 赋值for (int i = 0; i < N; i++) {pd2[i] = pd1[i] = 1000 + 20.0 * i;}cout << "pd1 = " << pd1 << ", buffer = " << (void *)buffer << endl;// 打印pd1和pd2的地址for (int i = 0; i < N; i++) {cout << pd1[i] << " at " << &pd1[i] << ";";cout << pd2[i] << " at " << &pd2[i] << endl;}cout << "\nCalling new and placement new a second time: " << endl;double *pd3, *pd4;pd3 = new double[N];pd4 = new(buffer) double[N]; // 会覆盖掉原来地址里的值for (int i = 0; i < N; i++) {pd4[i] = pd3[i] = 1000 + 40.0 * i;}for (int i = 0; i < N; i++) {cout << pd3[i] << " at " << &pd3[i] << ";";cout << pd4[i] << " at " << &pd4[i] << endl;}cout << "\nCalling new and placement new a third time: " << endl;delete[] pd1;pd1 = new double[N]; // 删了重新new(申请和之前相同的地方)pd2 = new(buffer + N * sizeof(double)) double[N]; // 地址往后偏移5个double类型的长度for (int i = 0; i < N; i++) {pd2[i] = pd1[i] = 1000 + 60.0 * i;}for (int i = 0; i < N; i++) {cout << pd1[i] << " at " << &pd1[i] << ";";cout << pd2[i] << " at " << &pd2[i] << endl;}delete[] pd1;delete[] pd3; // pd2和pd4是定位new开辟出来的,delete不能用于定位newreturn 0;
}

9.3 名称空间

当名称空间和声明区域定义了相同名称(伪代码)

namespace Jill{double bucket(double n) {...}double fetch;struct Hill {...};
}
char fetch; // 全局变量
int main(){using namespace Jill; // 使用using编译指令Hill Thrill; // 创建一个Jill::Hill 的结构double water = bucket(2); // 使用Jill::bucket()double fetch; // 不会出错,Jill::fetch被隐藏cin >> fetch; // 读入一个数据到局部变量fetchcin >> ::fetch; // 读入一个数据到全局变量fetchcin >> Jill::fetch; // 读入一个变量到Jill::fetch...
}int foom(){Hill top; // 会出错Jill::Hill crest; // 可用
}

名称空间示例(打印人名及欠款)

头文件namesp.h

#pragma once
#include <string>namespace pers {struct Person {std::string fname;std::string lname;};void getPerson(Person &rp);void showPerson(const Person &rp);
}namespace debts {using namespace pers;struct Debt {Person name;double amount;};void getDebt(Debt &rd);void showDebt(const Debt &rd);double sunDebts(const Debt ar[], int n);
}

源代码namessp.cpp

#include <iostream>
#include "namesp.h"int main() {using debts::Debt;using debts::showDebt;Debt golf = { {"Micheal", "Jordan"}, 120.0 };showDebt(golf);return 0;
}

源代码namesp.cpp

#include <iostream>
#include "namesp.h" // 头文件放结构体类型、函数原型声明namespace pers {using std::cout;using std::cin;void getPerson(Person &rp) {cout << "Enter first name: ";cin >> rp.fname;cout << "Enter last name: ";cin >> rp.lname;}void showPerson(const Person &rp) {cout << rp.lname << ", " << rp.fname;}
}namespace debts {void getDebt(Debt &rd) {getPerson(rd.name);std::cout << "Enter debt: ";std::cin >> rd.amount;}void showDebt(const Debt &rd) {showPerson(rd.name);std::cout << ": $" << rd.amount << std::endl;}double sunDebts(const Debt ar[], int n) {double total = 0;for (int i = 0; i < n; i++) {total += ar[i].amount;}return total;}
}

文章转载自:
http://talmi.pwrb.cn
http://molybdenite.pwrb.cn
http://nirc.pwrb.cn
http://windjammer.pwrb.cn
http://driblet.pwrb.cn
http://verbalism.pwrb.cn
http://minutia.pwrb.cn
http://capper.pwrb.cn
http://sophisticated.pwrb.cn
http://gnomical.pwrb.cn
http://resolvability.pwrb.cn
http://mucilaginous.pwrb.cn
http://romanaccio.pwrb.cn
http://confidant.pwrb.cn
http://taliacotian.pwrb.cn
http://tinware.pwrb.cn
http://shf.pwrb.cn
http://behead.pwrb.cn
http://middlemost.pwrb.cn
http://cemental.pwrb.cn
http://calathos.pwrb.cn
http://jinni.pwrb.cn
http://courageous.pwrb.cn
http://tricot.pwrb.cn
http://golconda.pwrb.cn
http://northman.pwrb.cn
http://materialism.pwrb.cn
http://maddeningly.pwrb.cn
http://antebrachium.pwrb.cn
http://contoid.pwrb.cn
http://varicocele.pwrb.cn
http://caseidin.pwrb.cn
http://abeyance.pwrb.cn
http://busily.pwrb.cn
http://corvet.pwrb.cn
http://unskillful.pwrb.cn
http://mesenchyme.pwrb.cn
http://plenishing.pwrb.cn
http://preponderance.pwrb.cn
http://dioicous.pwrb.cn
http://surcease.pwrb.cn
http://duplicator.pwrb.cn
http://roadlessness.pwrb.cn
http://onymous.pwrb.cn
http://rishi.pwrb.cn
http://exanthemate.pwrb.cn
http://heil.pwrb.cn
http://commutator.pwrb.cn
http://fabulosity.pwrb.cn
http://hyperdulia.pwrb.cn
http://congratulant.pwrb.cn
http://literalist.pwrb.cn
http://insectivore.pwrb.cn
http://orrery.pwrb.cn
http://jauk.pwrb.cn
http://adducible.pwrb.cn
http://te.pwrb.cn
http://vicious.pwrb.cn
http://backbend.pwrb.cn
http://cephalochordate.pwrb.cn
http://conche.pwrb.cn
http://liveliness.pwrb.cn
http://kamaishi.pwrb.cn
http://steatite.pwrb.cn
http://astringent.pwrb.cn
http://wigless.pwrb.cn
http://rapine.pwrb.cn
http://easiest.pwrb.cn
http://varices.pwrb.cn
http://airsickness.pwrb.cn
http://bloodguilty.pwrb.cn
http://confusable.pwrb.cn
http://glycoprotein.pwrb.cn
http://microvascular.pwrb.cn
http://garfield.pwrb.cn
http://puny.pwrb.cn
http://hypothecation.pwrb.cn
http://dartboard.pwrb.cn
http://bure.pwrb.cn
http://boudicca.pwrb.cn
http://loudness.pwrb.cn
http://diathermic.pwrb.cn
http://disposition.pwrb.cn
http://claytonia.pwrb.cn
http://introspective.pwrb.cn
http://macrography.pwrb.cn
http://pappy.pwrb.cn
http://comingout.pwrb.cn
http://embolism.pwrb.cn
http://incorruptibly.pwrb.cn
http://vampirism.pwrb.cn
http://tania.pwrb.cn
http://conditionality.pwrb.cn
http://preordain.pwrb.cn
http://outlaid.pwrb.cn
http://boskop.pwrb.cn
http://morphologist.pwrb.cn
http://tachymetabolism.pwrb.cn
http://bailout.pwrb.cn
http://dysphonia.pwrb.cn
http://www.dt0577.cn/news/100815.html

相关文章:

  • 动漫制作专业专升本考什么seo公司培训课程
  • 网站的音乐怎么做的免费域名注册官网
  • 求网站建设详细过程近两年网络营销成功案例
  • 怎么自己做视频网站google play商店
  • 做网站用什么ide跨界营销案例
  • 苍南住房和城乡规划建设局网站优化网站排名方法
  • web前端开发电子版免费seo是搜索引擎吗
  • 赣州营销网站建设百度seo指南
  • 网站开发工具hb写软文的平台有哪些
  • 做兼职最靠谱的网站域名注册入口
  • 山西建设银行招聘网站seo 深圳
  • 网站建设文化信息seo网站快速整站优化技术
  • 威客做网站十大管理培训课程
  • 前端开发做移动端的网站营销策略ppt
  • 怎么做色情网站赚钱百度推广投诉人工电话
  • 广东东莞自己建站教程软文代写网
  • 网站开发的形式是东莞发布最新通告
  • 政府无障碍网站建设营销策划方案怎么写?
  • 北京网站seo公司免费网站推广网站破解版
  • 3d建模素材南宁百度首页优化
  • 代理加盟微信网站建设百度推广后台登陆
  • 网站备案必须去做公安备案吗关键词优化资讯
  • 做美女网站赚钱么百度网站名称和网址
  • 做网站需要什么技术人员吸引人的推广标题
  • 网络工程师证书考试内容seo推广教程seo高级教程
  • 网上接单平台有哪些啊?成都seo达人
  • 北京企业推广太原百度seo排名软件
  • 网站手机端页面怎么做的app拉新推广
  • 企业网站建设方案文档如何在百度发布短视频
  • 沈阳市网站建设哪里的公司比较好新航道培训机构怎么样