中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當(dāng)前位置: 首頁 > news >正文

重慶網(wǎng)絡(luò)網(wǎng)站推廣網(wǎng)絡(luò)營銷公司排行榜

重慶網(wǎng)絡(luò)網(wǎng)站推廣,網(wǎng)絡(luò)營銷公司排行榜,百度多久收錄網(wǎng)站,怎么查詢網(wǎng)站有沒有做網(wǎng)站地圖9.1 單獨編譯 Visual Studio中新建頭文件和源代碼 通過解決方案資源管理器,如圖所示: 分成三部分的程序(直角坐標(biāo)轉(zhuǎn)換為極坐標(biāo)) 頭文件coordin.h #ifndef __COORDIN_H__ // 如果沒有被定義過 #define __COORDIN_H__struct pola…

9.1 單獨編譯

Visual Studio中新建頭文件和源代碼

通過解決方案資源管理器,如圖所示:

分成三部分的程序(直角坐標(biāo)轉(zhuǎn)換為極坐標(biāo))

頭文件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函數(shù),調(diào)用其他函數(shù))

#include <iostream>
#include "coordin.h" // 尖括號表明去系統(tǒng)目錄找,雙引號表明去當(dāng)前目錄找
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(其他函數(shù)的定義)

#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 存儲持續(xù)性、作用域和鏈接性

全局變量和局部變量

頭文件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內(nèi)部可見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限定符用于局部變量(統(tǒng)計字符串的字符個數(shù))

#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);// 如果輸入的內(nèi)容大于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,無論調(diào)用多少次這個函數(shù),該變量只會在第一次初始化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;// 用常規(guī)new運算符為N個double類型開辟內(nèi)存空間pd1 = new double[N];// 用定位new運算符為N個double類型開辟內(nèi)存空間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 名稱空間

當(dāng)名稱空間和聲明區(qū)域定義了相同名稱(偽代碼)

namespace Jill{double bucket(double n) {...}double fetch;struct Hill {...};
}
char fetch; // 全局變量
int main(){using namespace Jill; // 使用using編譯指令Hill Thrill; // 創(chuàng)建一個Jill::Hill 的結(jié)構(gòu)double water = bucket(2); // 使用Jill::bucket()double fetch; // 不會出錯,Jill::fetch被隱藏cin >> fetch; // 讀入一個數(shù)據(jù)到局部變量fetchcin >> ::fetch; // 讀入一個數(shù)據(jù)到全局變量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" // 頭文件放結(jié)構(gòu)體類型、函數(shù)原型聲明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://www.risenshineclean.com/news/4465.html

相關(guān)文章:

  • 開通網(wǎng)站必須做域名空間營銷方法有哪些方式
  • 怎么更改網(wǎng)站域名搜索引擎推廣實訓(xùn)
  • 瀏陽做網(wǎng)站報價簡述如何優(yōu)化網(wǎng)站的方法
  • 網(wǎng)站越來越難做班級優(yōu)化大師免費下載
  • 常德投訴網(wǎng)站經(jīng)典品牌推廣文案
  • 做網(wǎng)站的語言智慧營銷系統(tǒng)平臺
  • 17zwd一起做業(yè)網(wǎng)站做網(wǎng)站的公司有哪些
  • 公明網(wǎng)站建設(shè)seo網(wǎng)站有優(yōu)化培訓(xùn)班嗎
  • c 做的網(wǎng)站怎么上傳圖片廣告公司網(wǎng)站
  • 現(xiàn)在個人做網(wǎng)站還能盈利嗎百度400電話
  • 網(wǎng)站建設(shè)北京貴武安百度seo
  • 騰訊 微商 網(wǎng)站 建設(shè)青島神馬排名優(yōu)化
  • 一個人做商城網(wǎng)站網(wǎng)頁開發(fā)培訓(xùn)網(wǎng)
  • 專業(yè)制作彩鈴網(wǎng)站排名軟件
  • 電子商務(wù)網(wǎng)站服務(wù)器百度站長平臺網(wǎng)站提交
  • 做視頻播放網(wǎng)站百度問答庫
  • 為什么網(wǎng)站有不同的擴展名全國最新的疫情數(shù)據(jù)
  • 鄒城手機網(wǎng)站建設(shè)重慶網(wǎng)
  • 煙臺網(wǎng)站排名優(yōu)化報價seo排名優(yōu)化課程
  • 購物網(wǎng)站開發(fā)費用武漢百度信息流廣告
  • wordpress后臺亂了是怎么回事專業(yè)網(wǎng)站優(yōu)化公司
  • 建立讀音seo研究中心vip教程
  • dw怎么做網(wǎng)站教程廣告推廣網(wǎng)站
  • seo的網(wǎng)站建設(shè)湖南企業(yè)競價優(yōu)化公司
  • 云技術(shù)在網(wǎng)站建設(shè)中的應(yīng)用免費網(wǎng)絡(luò)推廣軟件
  • 模板手機網(wǎng)站建設(shè)公司濟南百度推廣優(yōu)化
  • 招遠建網(wǎng)站中國今天剛剛發(fā)生的新聞
  • 壽陽網(wǎng)站建設(shè)哈爾濱網(wǎng)絡(luò)推廣優(yōu)化
  • 想要找個網(wǎng)站做環(huán)評公示剛剛中國宣布重大消息
  • 讀書網(wǎng)站如何做職業(yè)技能培訓(xùn)網(wǎng)