自己写的一个练习程序
2012-08-29 18:06
267 查看
/* base.h */ #ifndef BASE_H #define BASE_H #include <string> #include <iostream> using namespace std; class Base{ public: Base(){} Base(string x_name, double x_price, int x_num):name(x_name), price(x_price), num(x_num){} void setName(string name){this->name = name;} string name; double price; int num; }; #endif
#include <vector> #include <fstream> #include "base.h" const int NUM = 2; int main() { ofstream output; output.open("wei.txt"); string in_name; double in_price; int in_num; vector<Base> iter; for (int i = 0; i != NUM; ++i) { cout << "Please enter name of book: "; cin >> in_name; cout << "Please enter price of book: "; cin >> in_price; cout << "Please enter number of book: "; cin >> in_num; Base book(in_name, in_price, in_num); iter.push_back(book); } /* for (int j = 0; j != NUM; ++j) { cout << iter[j].name << endl; cout << iter[j].price << endl; cout << iter[j].num << endl; } */ for (int j = 0; j != NUM; ++j) { output << iter[j].name << " " << iter[j].price << " " << iter[j].num << endl; } output.close(); ifstream input; input.open("wei.txt"); for (int k = 0; k != NUM; ++k) { input >> iter[k].name >> iter[k].price >> iter[k].num; cout << iter[k].name << " " << iter[k].price << " " << iter[k].num << endl; } input.close(); cout << "DONE!" << endl; return 0; }
相关文章推荐
- 手机直播程序开发搭建一个您自己的平台
- 自己私用的一个简单程序
- 练习1-21 编写程序entab,将空格串替换成最少数量的制表符和空格,但要保持单词之间的间隔不变。假设制表符终止位的位置与练习1-20的detab程序的情况相同。当使用一个制表符或者一个空格都可以到达下一个制表符终止位时,选用哪种替换字符比较好。
- linux系统编程综合练习-实现一个小型的shell程序(二)
- 自己写的一个简单的风速仪程序
- 练习1-19 编写函数 reverse(s),将字符串s 中的字符顺序颠倒过来。使用该函数编写一个程序,每次颠倒一个输入行中的字符顺序。
- 自己新建一个IDOC type和IDOC 触发程序
- C程序设计语言,练习1-13,编写一个程序,打印输入单词的直方图(垂直方向)
- 看了一个老师布置的C++作业,也顺便练习一下,提高一下自己
- 赛码网,股神问题,用C语言自己实现的一个程序,仅供参考
- 看到别人的Python爬虫博客,自己也模仿着写一个,顺便练习一下python
- 编写一个小程序,从标准输入读入一系列string对象,寻找连续重复出现的单词。程序应该找出满足一下条件的单词:该单词的后面紧接着再次出现自己本身。跟踪重复次数最多的单词及其重复次数,输出.
- 编写一个程序,开启3个线程,这3个线程的ID分别为A、B、C,每个线程将自己的ID在屏幕上打印10遍,要求输出结果必须按ABC的顺序显示;如:ABCABC….依次递推。
- 自己练习的文件操作小程序
- 自己写了一个简单的画图程序
- 用PHP程序为自己网站打造一个搜索引擎
- 写了一个程序用来处理字符串,把一张列表中的题目序号提取出来,然后跟自己昨晚的列表比较,找出来还没有做过的题目列表
- 书后练习--将输入复制到输出程序,并将其中连续的多个空格用一个空格代替
- 编写一个程序,开启3个线程,这3个线程的ID分别为A、B、C,每个线程将自己的ID在屏幕上打印10遍,要求输出结果必须按ABC的顺序显示;如:ABCABC….依次递推
- c# 控制台程序调用直接运行一个新程序和隐藏自己的窗体(转)