<
cout<<------------------<
cout<
#include <> 1 c<
int a[10]; double xy[10];
cout<
else if (score>=80) cout<
#include <> main() {
int n;
cout<<
=; cin>>n;
if (n>=0 && n<=100 &&n%2==0) cout<<
=<
cout<
int a,b,Max; .10
for(int i=1;i<=10;i++) cout<
for(int j=10;j>=1;j--) cout<
for(int k=1;k<=10;k=k+2) cout<
.
for(float x=0;x<=;x=x+ cout<
for(float x1=0;x1<=+2;x1=x1+ cout<
for(int n=1;n<=100;n++) s=s+n;
cout<
#include<> main() {
.+100
int s=0,n=1; while(n<=100) { s=s+n; n++; }
cout<
int s=0,n=0; do { n++; s+=n; }while(n<100);
cout<
cin>>st[i].name; cin>>st[i].maths; cin>>st[i].physics; cin>>st[i].chemistry; } otal=st[i].maths+st[i].physics+st[i].chemistry; um<<'\t';
cout<
#include<> main() {
ame=<<(*p).name<
cout<<(*p).sex=<<(*p).sex<
cout<
cout<
cout<<(*p).sex=<<(*p).sex<
cout<
cout<<----------------<
int int_values[] = {51, 23, 2, 44, 45,0,11}; float float_values[] = {, , , , }; student st_arr[]={101,WangLin,92,102,LiPing,85,103,ZhaoMin,88}; um<< ;
cout<
swap_Rec(&a[i],&a[j]); <<\ <
#include<>
void disp(void); <
#include<> <
cout<
cout<
cout<
cout<
cout<
cout<
cout<
cout<
cout<
fprintf(fp1,%d %s %f\n,st[i].num,st[i].name,st[i].grade);
} fclose(fp1); <
cout<
cout<
cout<
cout<
cout<
cout<
cout<
cout<
perror( Write error ); clearerr( stdin ); } /* See if read causes an error. */
printf( Will input cause an error? ); c = getc( stdin ); if( ferror( stdin ) ) {
perror( Read error ); clearerr( stdin ); } }
#include<> #include<> <
for (i=1; i<=MAX; i++) { cin>>x; (x); } <
~stack(void) << endl; << endl; }
<< endl; isp_count(); delete p; (); }
#include<> << endl; }
~ex_class() { cout << The Object destroyed. <
void set_value(int n);
void show_val(char *name); } ; <
#include<> um :; cout<
cout<<<
um=<
public: um=;
cout<<<
virtual void aFn2(void) { cout<
<
<
<
void aFn2(void) {
cout<
<
void aFn2(void){
cout<
cout<
cout<
#include<> #include <> ;
int n; 1.7320534f << endl; }
~stack(void) {
cout << Stack Destroyed. << endl; }
void push(T); T pop(void); }; << endl;
return; }
stck[tos++] = i; }
template
if(tos==0) {
cout << Stack underflow. << endl; return 0; }
return stck[--tos]; } irst;
cout<<,<<(*theIterator).second<< ; }
cout<
cout<<,<<(*theIterator).second<< ; }
cout<
cout<<,<<(*it).second<< ; } cout<
econd << ;
else cout << [err] ; }
cout << endl; } }
#include
#include
()=20; } //弹出栈中所有的数据并显示 cout<
while (!()) { cout<<()<< ; (); } cout<
#include
#include
//创建一个list容器的实例LISTINT,其存放int型数据 typedef list
void main(void) {
//用LISTINT创建一个名为listOne的list对象 LISTINT listOne;
//指定i为迭代器变量 LISTINT::iterator i;
LISTINT::reverse_iterator ir; //从前面向listOne容器中添加数据 (2); (1); //从后面向listOne容器中添加数据 (3); (4); //从前向后显示listOne中的数据 for (i = (); i != (); ++i) cout << *i << ; cout << endl; //从后向后显示listOne中的数据 for (ir =();ir!=(); ++ir) cout << *ir << ; cout << endl; //从键盘上输入数据 for (i = (); i != (); ++i) { cout<
#include #inclu
//在main()函数中测试accumulate算法 void main () {
//--------------------------------------------
// accumulate算法对于普通数组的计算 //--------------------------------------------- int x[]={1,3,5,7,9}; 潣瑵?硜嵛尺※
for (int i=0;i<5;i++) cout<
cout<
cout<
// accumulate算法对于vector容器的计算 //--------------------------------------------- //声明intvector容器和迭代器ii Int intvector; Int::iterator ii; //向intvector容器中插入元素 for (i=1; i<=5; i++) { (i); }; //显示intvector容器中的元素值和累加结果 cout << intvector: <
cout<
// accumulate算法对于list容器的计算 //--------------------------------------------- //声明list容器对象和迭代器 LISTINT::iterator iL; LISTINT list1; //向list1容器对象中插入元素并显示 (1); (3); (5); (2); (6); //显示list1容器的元素值和累加结果 cout << list1: <
cout<
SET_INT::iterator si;
//向set1容器中插入元素 (5); (20); (10); (15); (25); //显示set1容器的元素值和累加结果 cout <
cout<
#include #include
using namespace std; //产生指定范围的整数随机数 int getrand(int min,int max) { int m;
m=(max-min);
m=min+double(rand())/RAND_MAX*m ; return m; } //利用类模板生成实例 typedef vector < int > Int; typedef list
//-------------------------------------------- // count算法对于普通数组的计算 //--------------------------------------------- int x[size]; 潣瑵?硜嵛尺※
for (int i=0;i
cout<
cout<
//声明intvector容器和迭代器ii Int intvector; Int::iterator ii; //向intvector容器中插入元素 for (i=1; i
//显示intvector容器中的元素值和统计结果 cout << intvector: ; for (ii=();ii !=();++ii) cout<<(*ii)<< ; cout<
cout<
//-------------------------------------------- // count算法对于list容器的计算 //--------------------------------------------- //声明list容器对象和迭代器 LISTINT::iterator iL; LISTINT list1; //向list1容器对象中插入元素并显示 for (i=1; i
for (iL=();iL !=();++iL) cout<<(*iL)<< ; cout<
cout<
//-------------------------------------------- // count算法对于set容器的计算 //--------------------------------------------- //声明set容器对象和迭代器 SET_INT set1;
SET_INT::iterator si; //向set1容器中插入元素 for (i=1; i
for (si=();si !=();++si) cout<<(*si)<< ; cout<
cout<
#include
//如果字符串以'S'开头,则返回true int MatchFirstChar( const string& str) {
string s(S) ; return s == (0,1) ; } //测试count_if算法 void main() {
const int VECTOR_SIZE = 8 ; //生成成员类型为strings的vector容器类 typedef vector
cout << Number of elements that start with letter \S\ = << result << endl ; //显示NamesVect容器[1,6]之间的元素 cout <
for(it =&NamesVect[1]; it != &NamesVect[7]; it++) cout << *it << ; cout <<endl ; //统计并显示NamesVect容器的所有元素中以'S'字符开头的字符串 result = count_if(&NamesVect[1], &NamesVect[7], MatchFirstChar) ;
cout << Number of elements that start with letter \S\ = << result << endl ; }
#include
//显示vector容器中的元素 void put_vector(Int v) {
IntArray::iterator theIterator; for (theIterator=();theIterator!=();++theIterator){ cout<<(*theIterator)<< ; }
cout<
//-------------------------------------------- // fill和fill_n算法对普通数组的计算 //--------------------------------------------- int x[]={1,3,5,7,9}; 潣瑵??硜嵛?? put_array(x,5); //填数处理 fill(x+1,x+3,2);
cout <<
ill(x+1,x+3,2): <
cout <<
ill_n(x,3,8): <
//--------------------------------------------
// fill和fill_n算法对于vector容器的计算 //--------------------------------------------- //声明intvector容器和迭代器ii Int intvector; //向intvector容器中插入元素 for (int i=1; i<=10; i++) { (i); };
//显示intvector容器中的元素值和统计结果 cout << intvector: <
cout <<
ill(),()+3,2): <
put_vector(intvector); fill_n(&intvector[5],3,8);
cout <<
ill_n(&intvector[5],3,8): <
#include
#define ARRAY_SIZE 10 using namespace std; //利用类模板生成实例 typedef vector < int > Int; //显示数组 void put_array(int x[],int size) { for(int i=0;i
Int::iterator theIterator; for (theIterator=();theIterator!=();++theIterator){ cout<<(*theIterator)<< ; }
cout<
//-------------------------------------------- // find()算法对于普通数组的处理 //---------------------------------------------
int x[ARRAY_SIZE]={1,3,5,7,9,2,4,6,8,10}; 潣瑵??硜嵛??
put_array(x,ARRAY_SIZE); //find()算法查找,并显示查找结果 for(i=0;i<=2;i++) { cout<
p=find(x,x+ARRAY_SIZE,value); if (p != x + ARRAY_SIZE) { //查到 cout << First element that matches << value; cout<< is at location << p - x<< endl; }
else { //未查到 cout << The sequence does not contain any elements; cout<< with value << value << endl ; } }
//--------------------------------------------
// find()算法对于vector容器的处理 //--------------------------------------------- //声明intvector容器对象 Int intvector; //向intvector容器中插入元素 for (i=1; i<=10; i++) { (i); }; //显示intvector容器中的元素值 cout << intvector: ; put_vector(intvector); //find()算法查找,并显示查找结果 Int::iterator pos; for (i=0;i<=2;i++) { cout<
pos=find(),(),value); if (pos != ()) { //查到 cout << First element that matches << value; cout<< is at location <
else { //未查到 cout << The sequence does not contain any elements; cout<< with value << value << endl ; } } }
#include
#define ARRAY_SIZE 10 using namespace std; //利用类模板生成实例 typedef vector < int > Int; //显示数组 void put_array(int x[],int size) { for(int i=0;i
Int::iterator theIterator; for (theIterator=();theIterator!=();++theIterator){ cout<<(*theIterator)<< ; } } //在main()函数中测试find()_end()算法 void main () {
//--------------------------------------------
// find_end()算法对普通数组的处理 //---------------------------------------------
int x[ARRAY_SIZE]={1,3,5,7,9,2,4,6,8,10}; 潣瑵??硜嵛??
put_array(x,ARRAY_SIZE); cout<
cout<< is at location in x << p - x<< endl; }
else { //未查到 cout << The sequence does not contain any elements; cout<< with value ; put_array(&x[3],3); } //-------------------------------------------- // find_end()算法对vector容器的处理 //--------------------------------------------- //声明intvector容器对象 Int intvector; //向intvector容器中插入元素 for (int i=1; i<=10; i++) { (i); }; //显示intvector容器中的元素值 cout << intvector: ; put_vector(intvector); cout<
cout << emp: ; put_vector(temp); cout<
cout<< is at location in intvector <
else { //未查到 cout << The sequence does not contain any elements; cout<< with value ;
put_vector(temp); cout<< endl ; } }
#include
static int r;
static int f1 = 0; static int f2 = 1; r = f1 + f2 ; f1 = f2 ; f2 = r ; return f1 ; }
//返回一个Fibonacci数,其由generate()算法调用 int Fibonacci2(void) {
static int r;
static int f1 = 0; static int f2 = 1; r = f1 + f2 ; f1 = f2 ; f2 = r ; return f1 ; }
//定义整型数的vector容器类 typedef vector
IntVector::iterator theIterator; cout<
for (theIterator=();theIterator!=();++theIterator){ cout<<(*theIterator)<< ; }
cout<
const int VECTOR_SIZE = 15 ; //定义迭代器类 typedef IntVector::iterator IntVectorIt ; //声明vector容器对象 IntVector Numbers1(VECTOR_SIZE),Numbers2(VECTOR_SIZE); int i ; //初始化vector容器对象 for(i = 0; i < VECTOR_SIZE; i++)
Numbers1[i] = i ; //显示vector容器对象的元素 cout << Before calling generate_n: << endl ; put_vector(Numbers1,Numbers1); //利用generate_n算法用Fibonacci 数填充vector容器 generate_n(), VECTOR_SIZE, Fibonacci1) ; //显示vector容器对象的元素 cout << After calling generate_n: << endl ; put_vector(Numbers1,Numbers1); //利用generate算法用Fibonacci 数填充vector容器 generate(),(), Fibonacci2) ; //显示vector容器对象的元素 cout << After calling generate: << endl ; put_vector(Numbers2,Numbers2); }
#include
Int::iterator theIterator; for (theIterator=();theIterator!=();++theIterator){ cout<<(*theIterator)<< ; } cout<
//--------------------------------------------
// reverse()和reverse_copy()算法对普通数组处理 //--------------------------------------------- int x[]={1,3,5,7,9}; 潣瑵?硜嵛尺※ put_array(x,5); //reverse()反转x数组并显示 reverse(x,x+5); 潣瑵?硜嵛尺※
put_array(x,5); int y[]={2,4,6,8,10}; cout<
//--------------------------------------------
// reverse()和reverse_copy()算法对vector容器的处理 //--------------------------------------------- //声明intvector容器和迭代器ii Int intvector; //向intvector容器中插入元素 for (int i=1; i<=10; i++) { (i); }; //显示intvector容器中的元素值 cout << intvector: <
cout << intvector: <
reverse_copy()+2,()+7,()); cout << emp: <
#include
#define ARRAY_SIZE 15 using namespace std; //定义整型数的vector容器类 typedef vector
IntVector::iterator theIterator; cout<
for (theIterator=();theIterator!=();++theIterator){ cout<<(*theIterator)<< ; }
cout<
m=(max-min);
m=min+double(rand())/RAND_MAX*m ; return m; } //在main()函数中测试sort()和partial_sort()算法 void main () {
int i;
//--------------------------------------------
// sort()和partial_sort()算法对普通数组处理 //--------------------------------------------- //sort()算法处理数组,并显示 int x[ARRAY_SIZE];
for (i=0;i
潣瑵?硜嵛尺※
put_array(x,ARRAY_SIZE); sort(x,x+ARRAY_SIZE);
cout<
for (i=0;i
cout<
put_array(y,ARRAY_SIZE);
partial_sort(y+2,y+7,y+ARRAY_SIZE);
cout<
// sort()和partial_sort()算法对vector容器的处理 //--------------------------------------------- IntVector Numbers1,Numbers2; for(i=0;i<15;i++) { (getrand(1,30)); (getrand(1,30)); } put_vector(Numbers1,Numbers1); put_vector(Numbers2,Numbers2); //sort()算法处理并显示 sort(),()); cout<
cout<
#include
m=min+double(rand())/RAND_MAX*m ; return m; }
//在main()函数中测试max_element()和 min_element()算法 void main () {
//声明变量和数组 int i;
int x[ARRAY_SIZE]; //用1到100的随机数初始化数组,并显示 srand( (unsigned)time( NULL ) ); for (i=0;i
潣瑵?硜嵛尺※
put_array(x,ARRAY_SIZE); //对数组x使用max_element()算法,并显示 int *pMax=max_element(x,x+ARRAY_SIZE); cout<
本文来源:https://www.2haoxitong.net/k/doc/c5a0ebfdd8ef5ef7ba0d4a7302768e9951e76e90.html
文档为doc格式