zoukankan      html  css  js  c++  java
  • c++面向对象程序设计

    //EXERCISE 2.1
    //Write a program that reads integers from the standard input until the end of file and then prints the largest and the smallest values  
    
    #include<iostream>
    #include<fstream>
    using namespace std;
    int main()
     {
         int n,max=0,min=0;
         cout << "input the biggest number:"<<endl;
         cin >> n; 
         ifstream fin;
         fin.open("in.txt");
         int *a = new int[n];
          if(!fin)
         {
             cout <<"failure"<<endl;
             exit(0);
             
         }
         for(int i =0;i<n;i++)
         {
             fin >> a[i];
             if(a[max]<a[i])
             max =i;
             if(a[min]>a[i])
             min = i;
         }
         fin.close();
         cout << "the max is" << a[max]<<endl;
          cout << "the min is" << a[min]<<endl;
          delete[] a;
          return 0;
     }
     
     
     
    

      

     
     

     2.2 Write a program that echoes the standard input to the standard output,except that each tab is replaced by the approriate name of spaces.Assume that tabs are set evey 8 columns,unless the user specifies a different tab setting on the command line.(讲真。。。题目我没看懂)

    #include<iostream>
    #include<iomanip>
    using namespace std;
    int main()
    {
    	int a,b,c;
    	cin >>a>>b>>c;
    	cout <<setw(8) << a<<endl;
    	cout <<setw(8) << b<<endl;
    	cout <<setw(8) << c<<endl;
    	return 0;
    }
    

      2.3 write a function db1that takes an int argument and multiplies it by 2.Pass the argument by reference.

    #include<iostream>
    using namespace std;
    void db1(int&);
    int main()
    {
    	int x = 6;
    	db1(x);
    	cout << x <<end
    	return 0;
    	
    }
    
    void db1(int& ref)
    {
    	ref = 2 * ref;
    }
    

      

  • 相关阅读:
    【4】通过简化的正则表达式处理字符串
    水晶报表WEB方式下不打印的问题
    字符串处理总结(旧)
    【3】利用Word模板生成文档的总结
    这个教授的观点颇犀利
    互联网时代还需要看书吗?
    怎样更爽地看PDF杂志
    吐槽win7
    信息技术真有想象的那么靠谱吗?
    无线路由器桥接的设置
  • 原文地址:https://www.cnblogs.com/monica-yuki/p/4909168.html
Copyright © 2011-2022 走看看