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