• 实验七


    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;
    } 
    


  • 相关阅读:
    mysql 下 计算 两点 经纬度 之间的距离
    富爸爸财务自由之路
    Ubuntu16.04忘记MySQL5.7的root用户密码之解决方案
    Windowns下code: command not found
    Linux下CRMEB环境搭建
    PHP无法使用curl_init()函数
    请在mysql配置文件修sql-mode或sql_mode为NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
    apache不能解析php之解决办法
    windows上hexo: command not found
    SyntaxError: Non-ASCII character 'æ' in file csdn.py on line 7, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
  • 原文地址:https://www.cnblogs.com/flyingbrid-nest/p/9205130.html
Copyright © 2020-2023  润新知