C + + Object-oriented programming

Source: Internet
Author: User

EXERCISE 2.1
Write a program this reads integers from the standard input until the end of file and then prints the largest and the SM Allest values  

#include <iostream>#include<fstream>using namespacestd;intMain () {intn,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(inti =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's replaced by the Approria Te name of spaces. Assume that tabs is set Evey 8 columns,unless The user specifies a different tab setting on the command line. (To tell the truth ...) I didn't read the question.

#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 was 2.Pass the argument by reference.

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

  

C + + Object-oriented programming

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.