📄 random.cpp
字号:
#include<iostream.h>
#include<fstream.h>
#include<string.h>
#include<iomanip.h>
#include"Word声明.h"
#include<stdlib.h>
#include<time.h>
void random()
{
ifstream fin2("添加word.txt",ios::in);
char wd[40];
for(int k=0;!fin2.eof();k++)
{
fin2>>word1[k].english>>word1[k].chines;
}
fin2.close();
int record[70],count=0;;
for(int i=0;i<10;i++)
{
srand(time(0));
int x;
x=rand()%60+1;//产生一个{0 10}的随机数//rand()%(n-m+1)+m;
//ran[k]=x;k++;//记录所有产生的随即数
cout<<i+1<<". "<<setw(8)<<word1[x].chines<<" 第"<<x<<"个单词"<<endl;
cout<<"请输入单词"<<endl;
cin>>wd;
if(strcmp(word1[x].english,wd)==0)
{
cout<<"* * * * * * * * * * * * *恭喜你,答对了!* * * * * * * * * * *"<<endl;
}
else
{
record[count]=x;count++;
cout<<"答错了,再接再厉"<<endl;
cout<<"正确答案是:"<<word1[x].english<<endl;
}
}
ofstream aa("记录.txt");
if(!aa){cout<<"不能打开文件"<<endl;return;}
if(count!=0)
{
cout<<"没背过的单词数:"<<count<<endl;
cout<<"以下是没背过的单词"<<endl;
for(int j=0;j<count;j++)
{
cout<<word1[record[j]].english<<" ";
aa<<word1[record[j]].english<<" "<<word1[record[j]].chines<<" ";
}
}
else cout<<"恭喜你!你已通过测试"<<endl;
aa.close();
cout<<endl;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -