zoukankan      html  css  js  c++  java
  • 实验七

    11-7

    #include<iostream>
    using namespace std;
    int main(){
    	ios_base::fmtflags original_flags=cout.flags();//纪录初始条件 
    	cout<<812<<'|';
    	cout.setf(ios_base::left,ios_base::adjustfield);//左对齐 
    	cout.width(10);		//设置域宽 
    	cout<<813<<815<<'
    ';
    	cout.unsetf(ios_base::adjustfield);		//取消调整 
    	cout.precision(2);
    	cout.setf(ios_base::uppercase|ios_base::scientific);//用科学计数法输出 
    	cout<<831.0;
    	cout.flags(original_flags);		//恢复初始化 
    	return 0;
    } 
    

    11-3

    #include<iostream>
    #include<fstream>
    using namespace std;
    int main(){
    	ofstream file("text1.txt");
    	if(!file){
    		cout<<"文件打开失败..."<<endl;
    	} 
    	file<<"已成功写入文件"<< endl;
    	file.close();
    	return 0;
    } 
    


    11-4

    #include<iostream>
    #include<fstream>
    #include<string>
    using namespace std;
    int main(){
    	ifstream file("text1.txt");
    	if(!file){
    		cout<<"文件打开失败..."<<endl;
    	} 
    	string s1;
    	file>>s1;
    	cout<<s1<<endl;
    	file.close();
    	return 0;
    } 
    

    list.cpp

    #include<iostream>
    #include<fstream>
    #include<vector>
    #include<string>
    #include<iomanip>
    #include<ctime>
    using namespace std;
    class Student{
    	public:
    		int num;
    		long long int number;
    		string names;
    		string classes;
    };
    int main(){
    	srand(time(NULL));
    	ifstream list("C:\Users\Admin\Desktop\fishc.c\list.txt");
    	ofstream roll("C:\Users\Admin\Desktop\fishc.c\roll.txt");
    	if(!list){
    		cout<<"文件打开失败..."<<endl;
    	}
    	if(!roll){
    		cout<<"文件打开失败..."<<endl;
    	}
    	vector<Student> data;
    	Student newdata;
    	while(list>>newdata.num>>newdata.number>>newdata.names>>newdata.classes){
    		data.push_back(newdata);
    	}
    	list.close();
    	roll.close();
    	char choice;
    	cout<<"是否开始点名?YES(Y)/NO(N)"<<endl;
    	while(cin>>choice){
    		int rollnum;
    		if(choice=='N'){
    			break;
    		} 
    		rollnum=rand()%data.size();
    		cout<<setw(10)<<left<<data[rollnum].num<<setw(20)<<left<<data[rollnum].number<<setw(10)<<left<<data[rollnum].names<<setw(10)<<left<<data[rollnum].classes<<endl;
    		cout<<"是否继续点名?YES(Y)/NO(N)"<<endl;
    	}
    	return 0;
    } 
    

    english.cpp

    #include<iostream>
    #include<string>
    #include<fstream>
    using namespace std;
    int main(){
    	string fielnames;
    	cin>>fielnames;
    	ifstream ifiel(fielnames);
    	if(!ifiel){
    		cout<<"文件打开失败...."<<endl; 
    	}
    	char ch;
    	int ch_num=0;
    	int word_num=0;
    	int l_num=0;
    	while(ifiel>>ch){
    		if(ch==' '||ch==','||ch=='.'||ch=='!'||ch=='?'){
    			word_num++;
    			ch_num++;
    		}else if(ch=='
    '){
    			l_num++;
    		}else{
    			ch_num++;
    		}
    	}
    	cout<<"ch="<<ch_num<<" word="<<word_num<<" line="<<l_num<<endl;
    	ifiel.close();
    	return 0;
    } 
    


  • 相关阅读:
    追随自己的价值观:用研经理 Anne Diaz 职业探索之路
    语义化版本(SemVer)的范围
    git如何放弃所有本地修改
    将本地已有的一个项目上传到新建的git仓库的方法
    using supervisord to run lsyncd script
    sersync下载安装及配置(有演示示例)
    sersync+rsync原理及部署
    Rsync+sersync 实现数据实时同步
    在分屏浏览中并排使用两个 Mac App
    MacOS 安装 Astah Professional 7.2
  • 原文地址:https://www.cnblogs.com/flyingbrid-nest/p/9205130.html
Copyright © 2011-2022 走看看