c++
leafinsnowfield
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
第五章作业
第一题:#include //比较3种不同类型数的大小 using namespace std; template Type1 GetMax(Type1 x,Type2 y,Type3 z) { cout<<"max:"; if(x>y) { if(x>z) return x; else return z; } else return y; } void mai原创 2015-05-18 16:35:54 · 402 阅读 · 0 评论 -
实用程序软件包(关于使用静态函数报错问题“Static function declared but not defined in C+++ "eh.h is only for C++!"报错问题)
#ifndef _UTILITY_H_//加static时,表示静态函数只在这个文件里用,那么编译器就在这个文件里找,没找到定义,就可以确定是未定义了; //不加static,表示静态函数可能在其他文件里,但是编译时没找到,又不能确定是哪个文件应该有,所以报没有链接错误。 #define _UTILITY_H_ //***ANSI C++ #include #include #include原创 2015-07-25 21:56:41 · 3385 阅读 · 0 评论 -
实用软件程序包包含的头文件
//***ANSI C++ #include #include #include #include #include #include #include #include #include #include #include #include //****ANSI C++end //旧版C++标准库头文件 #include #include #include #inc原创 2015-07-25 17:03:20 · 560 阅读 · 0 评论 -
c++模板选择排序
#ifndef _BUBBLESORT_H_//bubblesort.h #define _BUBBLESORT_H_ #define MAX_SIZE 100 #include using namespace std; //template template class DataList { private: ElemType data[MAX_SIZE]; int size; void原创 2015-07-25 16:06:34 · 691 阅读 · 0 评论 -
插入排序
void InsertSort(ElemType a[],int n) { for(int i=0;i<n;i++) { for(int j=i;j>0&&a[j]<a[j-1];j--)//后一个数比前一个数大不需要交换,应为前面的数都已经排好顺序,只有后一个数比前一个数小的时候则需要循环依次把数放到应该的位置 { Swap(j,j-1); } } }原创 2015-07-25 16:30:46 · 254 阅读 · 0 评论 -
c++文件
#include #include using namespace std; #include //system() exit() #define MAX_LINE_LENGTH 100 int main(int argc,char *argv[]) { if(argc!=2) { cout<<"用法:ShowFile文本文件名"<<endl; system("PAUSE");原创 2015-07-25 16:08:49 · 394 阅读 · 0 评论 -
c++动态内存分配
#include #include using namespace std; #include #include #define MAX_LINE_LENGTH 100 int main(int argc,char *argv[]) { ifstream *inFilePtr; char *strPtr,*strFileNamePtr; strPtr=new char [MAX_L原创 2015-07-25 16:06:51 · 414 阅读 · 0 评论 -
绩点计算机代码
smain_Calculator.cpp #include "sCalculator.h" char GetChar() { char ch; while((ch=cin.get())==' '||ch=='\t'||ch=='\n'); return ch; } void main()//显示全部成绩,必修成绩,全部绩点,部分绩点,平均分,Student修改密码,CManager录入学生原创 2015-05-26 00:23:41 · 559 阅读 · 0 评论 -
给定2个数字,并将这两个数范围内的所有数输出,并使得每行输出不超过10个数
#include int main() { std::cout<<"Enter two numbers:"<<std::endl; int v1,v2; std::cin>>v1>>v2; int lower,upper; if(v1<=v2) { lower=v1; upper=v2; }else { lower=v2; upper=v1; } std::c原创 2015-06-06 01:25:44 · 775 阅读 · 0 评论 -
关于while(std::cin>>value)
#include int main() { int sum=0,value; while(std::cin>>value) sum+=value; std::cout<<"Sum is:"<<sum<<std::endl; return 0; }注意:如果流是有效的,那么测试成功,遇到文件结束符或者遇到无效输入时,如读取了一个不是整数的值,则istream对象时无效的,处于无效状态的原创 2015-06-06 01:13:57 · 654 阅读 · 0 评论 -
第八章作业
#include "CMyString.h"//CMyString.cpp using namespace std; CMyString CMyString::operator+(CMyString &obj) { cout<<"重载运算符+"<<endl; char *p=new char[m_length]; for(int k=0;k<m_length;k++) p[k]=m_p[原创 2015-06-03 21:45:25 · 382 阅读 · 0 评论 -
标准类型和类类型之间的类型转化8_3
#include #include using namespace std; //利用指针传值 char *TestPointerForwardValue(char *pChar2) { char *pChar=new char[strlen(pChar2)+1]; if(NULL==pChar) { exit(0); } strcpy(pChar,pChar2); retur原创 2015-06-01 16:27:52 · 441 阅读 · 0 评论 -
异常处理8_5
#include #include using namespace std; void MyFunc(void); class CMyException//定义异常类 { public: CMyException(){}; ~CMyException(){}; const char *ShowExceptionReason()const { return "CMyExceptio原创 2015-06-01 16:54:37 · 335 阅读 · 0 评论 -
命名空间8_6
namespace //这里的命名空间没有具体的名字,可以定义没有名字的命名空间,注意 { int Function {;} }#include #include "MyNameSpace.h" #include "YourNameSpace.h" using namespace std; int iNum=10000;//全局变量 namespace MyNameSpace { in原创 2015-06-01 17:26:12 · 444 阅读 · 0 评论 -
绩点计算器的mfc代码
#ifndef __AFXWIN_H__//绩点计算器3.h #error include 'stdafx.h' before including this file for PCH #endif #include "resource.h" // main symbols #ifndef _SCALCULATOR_H_ #define _SCALCULATOR_H_ #include #原创 2015-06-01 00:18:35 · 1206 阅读 · 0 评论 -
绩点计算机原来的代码
#include "sCalculator.h"//main.cpp #include char GetChar() { char ch; while((ch=cin.get())==' '||ch=='\t'||ch=='\n'); return ch; } void main()//显示全部成绩,必修成绩,全部绩点,部分绩点,平均分,Student修改密码,CManager录入学生信息原创 2015-05-31 23:07:43 · 577 阅读 · 0 评论 -
第四章作业
4_1 #ifndef _SCLASS4_1_CEMPLOYEE_H_ #define _SCLASS4_1_CEMPLOYEE_H_ #include using namespace std; class CEmployee { public: CEmployee(float salary=2000) { m_salary=salary; } virtual ~CEmploye原创 2015-05-01 22:14:50 · 356 阅读 · 0 评论 -
第七章作业
第一题#include #include #include using namespace std; void main() { fstream file; char ch; file.open("test.txt",ios::out); char s[20]; cout<<"输入一段最多为19个字符的话语:直到输入为cirl+x结束:"<<endl; cin>>s; fi原创 2015-05-18 16:36:35 · 373 阅读 · 0 评论 -
数字逻辑最终正确版
#include char GetChar(); void main() { char c='5'; char A='5',B='5',C='5',D='5',E='5',F='5'; int z=0; for(;;)//A cirlce { c=GetChar(); switch(c)//A { case '1': printf("%d",z);//out原创 2015-06-17 00:07:32 · 706 阅读 · 0 评论 -
eof()
#include using namespace std; char GetChar(istream&in=cin)//从输入流in中跳过空格以获取一字符 { char ch; int a=1; while(!in.eof()&&(ch=in.get())==' ');//先读取到文件结束符再结束 return ch; } int main() { char ch; cout原创 2015-05-17 17:11:29 · 568 阅读 · 0 评论 -
putback()
#include using namespace std; char GetChar(istream&in=cin) { char ch; while((ch=cin.get())==' '&&in.peek()!=EOF) ; return ch; } int main() { char ch; char x; ch=GetChar(); while(ch!='\n'&&原创 2015-05-17 17:08:24 · 679 阅读 · 0 评论 -
put()
#include using namespace std; int main() { char s[]="Hello,World!"; for(int i=0;i<strlen(s);i++) cout.put(s[i]);//cout.put(ch)输出单个字符 cout<<endl; system("PAUSE"); return 0; }原创 2015-05-17 17:13:17 · 418 阅读 · 0 评论 -
peek()
#include using namespace std; char GetChar(istream&in=cin) { char ch; while(in.peek()!=EOF&&(ch=cin.get())==' '); //cout<<"ch="<<ch<<endl; return ch; } int main() { char ch; cout<<"请输入一行字符串:"<原创 2015-05-17 17:10:49 · 748 阅读 · 0 评论 -
get()
#include using namespace std; int main() { char ch; cout<<"输入一行字符:"<<endl; ch=cin.get(); while(ch!='\n') { cout.put(ch); ch=cin.get(); } cout<<endl; system("PAUSE"); return 0; }原创 2015-05-17 17:12:00 · 372 阅读 · 0 评论 -
getline()
#include using namespace std; int main() { char s[256]; cout<<"输入一行的字符:"<<endl; cin.getline(s,8); cout<<s<<endl; system("PAUSE"); return 0; }原创 2015-05-17 17:12:05 · 433 阅读 · 0 评论 -
8_1
#include #include using namespace std; const int LEN=5; class CNode { public: CNode(int value =0); void Print()const; private: int m_value; }; CNode::CNode(int value):m_value(value) { ; } void原创 2015-05-27 19:26:19 · 424 阅读 · 0 评论 -
第四章作业 结点指针的回收又利用+排序+查找
main中#include #include "sclass4_11_Node.h" int CNode::sNodeNum=0; void main() { int now; int k; cout<<"1*************************************************."<<endl;//主要观察拷贝构造函数和new以及delete的作用 CNo原创 2015-05-17 00:08:02 · 336 阅读 · 0 评论 -
第四章作业补+排序+查询
main主程序中#include #include "sclass4_11_Node.h" int CNode::sNodeNum=0; void main() { int now; int k; cout<<"1*************************************************."<<endl;//主要观察拷贝构造函数和new以及delete的作用原创 2015-05-16 23:20:42 · 316 阅读 · 0 评论 -
第四章作业补
main程序#include #include "sclass4_11_Node.h" int CNode::sNodeNum=0; void main() { cout<<"1*************************************************."<<endl;//主要观察拷贝构造函数和new以及delete的作用 CNodeArray oCNA1; {原创 2015-05-16 14:52:05 · 329 阅读 · 0 评论 -
第三章作业
3_5 #include "sclass3_5_CPerson.h" void CPerson::Show()const { cout<<"name="<<m_name<<endl; cout<<"age="<<m_age<<endl; cout<<"sex="<<m_sex<<endl; cout<<"address="<<m_address<<endl; cout<<"teleph原创 2015-05-01 21:56:30 · 401 阅读 · 0 评论 -
第二章的作业
第2章第5题 #include "2_5CInteger.h" void main(void) { CInteger c(5),d(10),sum; cout<<"c的value"<<c.GetValue()<<endl;//主意函数有括号 cout<<"c的value"<<d.GetValue()<<endl; sum.AddValue(c,d); cout<<"总和:"<<sum.原创 2015-05-01 21:52:41 · 375 阅读 · 0 评论 -
运算符重载
1运算符重载将赋予已有运算符新含义,并需要明确改运算符的作用域范围。 2运算符重载属于静态多态性,整个过程是在编译阶段完成的。 3调用位置主要与运算符的作用域相关,在不同的作用域内可能定义了相同的运算符。 4运算符重载:c++中一下运算符只能重载为成员运算符: = () 【】 -> 5c++中>只能重载为友元函数。 成员函数的第一操作数为本类对象,因此当运算符重载为类的成员函数时原创 2015-05-01 22:32:26 · 414 阅读 · 0 评论
分享