【醒目】【高能预警】经验总结

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Loi_Shirley/article/details/52986279

——来自Loi57的经验

1.数组开小&&开大
2.memset用法
3.文件操作要写在主函数里
4.int && long long
5.n,m写反
6.短路运算符 && ||
7.输入输出要按照格式 不能忘记换行符
8.认真读题认真读题认真读题
9.保证代码不会CE //不能多打;之类的
10.学会算空间!!
11.滚动数组的重要性
12.先写暴力。

阅读更多
换一批

debug醒目 ssd5醒目

11-21

//main.cpprnrn#include rn#include rn#include rn#include rnrnusing namespace std;rnrn#include "course.h"rn#include "safearray.h"rnrnvoid init_courses(safearray);rnvoid display_menu(safearray);rnrnconst int NUM_COURSES = 10;rnconst int QUIT = 99;rnrnint main(int argc, char* argv[]) rnrnrn safearray courses(NUM_COURSES);rn init_courses(courses);rn rn int choice = 0;rn while (choice != QUIT) rn rn rn display_menu(courses);rn cout << "Enter number of course to see more information on\n";rn cin >> choice;rn cout << "\n";rnrn if (choice >= 1 && choice <= NUM_COURSES) rn rn cout << courses[choice - 1] << "\n\n";rn rn cout<<"a"< courses) rnrnrn for (int i = 1; i <= NUM_COURSES; i++) rn rn cout << i << ". " << courses[i - 1].name << "\n";rn rn cout << "99. Quit\n";rnrnrnvoid init_courses(safearray courses) rnrn rn ifstream inf("courses.txt");rn if (! inf) rn rn cerr << "Could not open courses.txt" << endl;rn exit(EXIT_FAILURE);rn rn rn for (int i = 0; i < NUM_COURSES; i++) rn rn inf >> courses[i]; rn rn rn inf.close();rnrnrn//safearray.hrnrn#ifndef SAFEARRAY_Hrn#define SAFEARRAY_Hrnrntemplate rnclass safearray rnrn private:rn T *storage;rn int capacity;rn rn public:rn safearray() : storage(NULL), capacity(0) // default constructorrn safearray(int size)rn rn storage= new T[size];rn capacity=size;rn rn ~safearray(void)delete []storage ;rnrn T& operator[] (int i) throw(out_of_range) rn rn if(i<0)rn throw(out_of_range)("err: input < 0");rn else if(i>capacity)rn throw(out_of_range)("err: input > max");rn elsern return *(storage+i);rn rnrn;rnrnrn#endifrnrn//course.hrnrn#ifndef COURSE_Hrn#define COURSE_Hrnrnint const MAX_LINES = 10;rnrnclass course rnrn public:rn string name;rn string title;rn string description[MAX_LINES]; rn rn course() : name(""), title("") rn course(string name, string title) : rn name(name), title(title) rnrn friend ostream& operator<<(ostream&, const course&); rn friend istream& operator>>(istream&, course&);rn;rnrnostream& operator<<(ostream& out, const course& c) rnrn out << c.name << ": " << c.title << "\n";rnrn int index = 0;rn while (c.description[index] != "") rn out << c.description[index++] << "\n"; rn rnrn return out;rnrnrnistream& operator>>(istream& in, course& c) rnrn getline(in, c.name);rn getline(in, c.title);rnrn string line;rn getline(in, line);rn int number = 0;rn while (line != "") rn c.description[number++] = line;rn getline(in, line);rn rn rn return in;rnrnrn#endifrnrnrn

没有更多推荐了,返回首页