C++课程设计__学生(成绩)信息管理系统__包括.doc报告文档,.exe可执行文件,.cpp源代码,以及.txt格式源
- 格式:doc
- 大小:266.00 KB
- 文档页数:23
打印出系统时间 优点:利用系统函数,还能修改系统时间,此文件必须是c++文件 1. #include< cstdlib > 2. #include< iostream> 3. using namespace std; 4. void main() 5. { 6. system("time"); 7. } 运行效果如下:
但是如果system里面的参数变为:time/t,就不允许修改系统时间了(缺点:仅仅显示小时和分钟) #include using namespace std; void main() { system("time/t"); system("pause"); }
改变DOS字体颜色 #include using namespace std; void main() { system("color ob"); system("pause"); } 注:当system(“color ob”)中的ob变为相应的数字时,DOS屏幕字体变为相应的颜色 改变DOS标题 #include using namespace std; void main() { system("title 王万腾"); system("pause"); }
打印出系统日期 #include using namespace std; void main() { system("date"); system("pause"); }
#include using namespace std; void main() { system("date/t"); system("pause"); }
for_each的简单应用 #include #include #include #include //特别注意:for_each()还是在algorithm头文件中定义的来 using namespace std; void print_i(int t) { cout<} int main() { int a[]={1,2,3,4,5,6,7,8,9,10,11,12,13}; vector elements(a,a+13); for_each(elements.begin(),elements.end(),print_i); cout #include #include using namespace std; int main() { string s("WangWanteng"); string::size_type len2=s.size(); cout<<"s.capacity():" 上例:s.substr(4,3)是指从s串第(4+1)个字符开始往后数3个字符 返回 关于swap()的传说 #include #include using namespace std; int main() { string s("Wangwanteng"); string s1("王万腾"); swap(s,s1); int a=1; int b=2; swap(a,b); cout class biggerThanThree { public: bool operator()(int val) const { return val > 3; } }; If we create an instance of class biggerThanThree, every time we reference this object using the function call syntax, the function call operator member function is invoked. To generalize this class, we add a constructor and a constant data member, which is set by the constructor: class biggerThan { public: const int testValue; biggerThan(int x) : testValue(x) { } bool operator()(int val) const { return val > testValue; } }; The result is a general biggerthanX function, where the value of X is determined when we create an instance of the class. We can do so, for example, as an argument to one of the generic functions that require a predicate. In this manner the following code finds the first value in a list that is larger than 12: std::list::iterator firstBig = std::find_if(aList.begin(), aList.end(), biggerThan(12)); 3.2.2 Use There are a number of situations where it is convenient to substitute function objects in place of functions: to use an existing function object provided by the C++ Standard Library instead of a new function; to improve execution by using inline function calls; and to allow a function object to access or set state information that is held by an object. Let's deal with each of these in the next three sections. 3.2.2.1 To Employ Existing C++ Standard Library Function Objects Table 5 illustrates the function objects provided by the C++ Standard Library. Table 5: Function objects provided by the C++ Standard Library Function object Implemented operations Arithmetic functions plus addition x + y minus subtraction x - y multiplies multiplication x * y divides division x / y modulus remainder x % y negate negation - x Comparison functions equal_to equality test x == y not_equal_to inequality test x != y greater greater-than comparison x > y less less-than comparison x < y greater_equal greater than or equal comparison x >= y less_equal less than or equal comparison x <= y Logical functions logical_and logical conjunction x && y logical_or logical disjunction x || y logical_not logical negation ! x Let's look at a couple of examples that show how these might be used. The first example uses std::plus() to compute the by-element addition of two lists of integer