实验六

csc13813017371 csc13813017371     2022-12-20     478

关键词:

1

合并文件,添加语句

#include<iostream>
#include<fstream>
#include<string>
#include<cstdlib>
using namespace std;
int main()
string filename;
cout << "输入打开的文件: ";
cin >> filename;
ofstream fout;
fout.open(filename,ios_base::app);
if(!fout.is_open())
cerr << "fail to open " << filename << endl;
system("pause");
exit(0);

fout << endl << "merge successfully" << endl;
return 0;

技术图片

 

 

2

main.cpp

#include <iostream>
#include<fstream>
#include <string>
#include <cstdlib>
#include<sstream>
#include<ctime>
#include "utils.h"
using namespace std;
int main()
ifstream fin;
ofstream fout;
string filename1;
int num, totalline = 0;
cout << "输入名单列表文件名:";
cin >> filename1;
cout << "输入随机抽点人数:";
cin >> num;
fin.open(filename1, ios_base::in);
if (!fin.is_open())
cerr << "fail to open file " << filename1 << endl;
system("pause");
exit(0);

string temp;
string a[100];
if (fin)
while (getline(fin, temp))
a[totalline++] = temp;

fin.close();


string filename;
filename = getCurrentDate()+".txt";
cout << "new file name is "<<filename << endl;
srand(std::time(0));
for (int i = 0;i < num;i++)

int line;
int random = rand();
line = rand()%totalline ;
cout << a[line] << endl;
fout.open(filename, ios_base::app);
fout << a[line] << endl;
fout.close();


system("pause");
return 0;

utils.h

//这个头文件里包含了可用工具函数的声明

#include <string>
using std::string;

// 函数声明
// 返回当前系统时间,格式诸如20190607
string getCurrentDate();

 

utils.cpp

#include "utils.h"
#include <ctime>
using std::string;

const int SIZE = 20;

// 函数功能描述:返回当前系统时间
// 参数描述:无参数
// 返回值描述:以string类型返回系统当前日期,格式诸如20190611
string getCurrentDate()

time_t time_seconds = time(0);
struct tm now_time;
localtime_s(&now_time, &time_seconds); // 使用了更安全的localtime_s()

char date[SIZE];

strftime(date, SIZE, "%Y%m%d", &now_time);

return (string(date));

技术图片

 

 

3

main.cpp

#include<iostream>
#include<fstream>
#include<string>
using namespace std;
int main()

int i = 0, zifu = 0, danci = 0, hangshu = 1;
char ch;
char s[100];
string filename;
ifstream file;
cout << "输入要统计的英文文本文件名:";
cin >> filename;
file.open(filename);
while ((ch = file.get()) != EOF)

s[i] = ch;
if (ch != ‘\\n‘)
zifu += 1;
else if (ch == ‘\\n‘)
hangshu += 1;
i++;

for (i = 0; i < 100; i++)

if (s[i] != ‘ ‘&&s[i] != ‘,‘&&s[i]!=‘.‘&&s[i + 1] == ‘ ‘)
danci += 1;
else if (s[i] != ‘ ‘&&s[i] != ‘.‘&&s[i] != ‘,‘&&s[i + 1] == ‘.‘)
danci += 1;
else if (s[i] != ‘,‘&&s[i] != ‘ ‘&&s[i]!=‘.‘&&s[i + 1] == ‘,‘)
danci += 1;

cout << "字符数:" << zifu << endl;
cout << "单词数:" << danci << endl;
cout << "行数:" << hangshu << endl;
system("pause");
return 0;

技术图片

 

实验六

任务三:defis_valid(x):ls=[str(i)foriinrange(0,10)]ls.append('X')iflen(x)<18:returnFalseforainrange(len(x)):ifx[a]notinls:returnFal 查看详情

实验六(代码片段)

实验六chip类#include<iostream>usingnamespacestd;classbaseprivate:inta,b;public:base(intx,inty):a(x),b(y)intadd()constreturna+b;;classA:publicbaseprivate:inta,b;public:A(intx,inty):base(x,y),a 查看详情

实验六(代码片段)

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465#include<stdio.h>constintN=5;//定义结构体类型structstudent,并定义STU为其别名typedefstru 查看详情

实验六

#include<stdio.h>#include<string.h>#defineN3typedefstructstudent intid; charname[20]; charsubject[20]; floatperf; floatmid; floatfinal; floattotal; charlevel[10];STU;voidcalc(STU[],int); 查看详情

网络攻防_实验六

               查看详情

实验六201771010101白玛次仁

第五章 继承总结实验六继承定义与使用实验时间2018-9-281.类,超类与子类继承Employee类来定义Manager类格式,关键字extends表示继承。Class新类名(子类(subclass),派生类(derivedclass)或孩子类(chideclass))。extends已有类名(超类... 查看详情

实验六信息搜集

实验六信息搜集实验要求2.实践内容(1)各种搜索技巧的应用(2)DNSIP注册信息的查询(3)基本的扫描技术:主机发现、端口扫描、OS及服务版本探测、具体服务的查点(4)漏洞扫描:会扫,会看报告,会查漏洞说明,会修补... 查看详情

实验六

1合并文件,添加语句#include<iostream>#include<fstream>#include<string>#include<cstdlib>usingnamespacestd;intmain()stringfilename;cout<<"输入打开的文件:";cin>>filename;ofstreamfout 查看详情

实验六

#include<stdio.h>#include<stdlib.h>#include<string.h>#defineN3 //运行程序输入测试时,可以把N改小一些输入测试typedefstructstudent intid; /*学生学号*/ charname[20]; /*学生姓名*/ charsubject[20]; /*考试科目*/ 查看详情

实验六(代码片段)

#实验三fromturtleimport*#绘制正方形#参数size指定边长,rgb指定画笔颜色#如果没有给参数,采用默认值defsquare(size=50,rgb=\'orange\'):pencolor(rgb)foriinrange(4):fd(size)left(90)defmain():setup(800,600)speed(0)foriinrange(10):square(80)le 查看详情

实验六

 心得:在此次实验中,我了解到了函数的具体调用过程,但仍然需要继续练习将函数调用掌握。1.函数的定义 2.函数的调用  3.参数传递  4.函数结果返回 5.函数原型声明 #include<stdio.h>#include<mat... 查看详情

实验六(代码片段)

实验任务1#include<stdio.h>#include<stdlib.h>#include<string.h>#defineN3//运行程序输入测试时,可以把N改小一些输入测试typedefstructstudentintid;/*学生学号*/charname[20];/*学生姓名*/charsubject[20];/*考试科目*/floatperf;/ 查看详情

实验六(代码片段)

实验任务1:#include<stdio.h>#include<stdlib.h>#include<string.h>#defineN3//运行程序输入测试时,可以把N改小一些输入测试typedefstructstudentintid;/*学生学号*/charname[20];/*学生姓名*/charsubject[20];/*考试科目*/floatperf; 查看详情

数据结构-实验六排序

实验六  排序 l 实验目的1、排序的基本概念     1.掌握在数组上进行各种排序的方法和算法。     2.深刻理解各种方法的特点,并能灵活应用。     3.加深对排... 查看详情

实验六(代码片段)

 1.验证性实验#include<iostream>#include<fstream>#include<string>#include<cstdlib>usingnamespacestd;intmain()stringfilename1,filename2,newfilename;cout<<"输入要合并的两个文件名:";ci 查看详情

实验六(代码片段)

fromturtleimport*defsquare(size=50,rbg=\'blue\'):pencolor(rbg)foriinrange(4):fd(size)left(90)setup(800,600)speed(0)foriinrange(10):square()left(36)hideturtle()done()fromturtleimport*setup(800,600)penc 查看详情

实验六

1.1#include<stdio.h>#defineN4intmain()intx[N]=1,9,8,4;inti;int*p;//方式1:通过数组名和下标遍历输出数组元素for(i=0;i<N;++i)printf("%d",x[i]); 查看详情

mooc《linux操作系统编程》学习笔记-实验六(代码片段)

实验六线程同步实验https://www.icourse163.org/learn/UESTC-1003040002?tid=1455108444#/learn/content?type=detail&id=1228729539&cid=1245454470实验六 线程同步实验https://www.icourse163.org/learn/UESTC-1003040002?tid=14 查看详情