Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The following homework is regarding C++ in unix System With console logging enab

ID: 3781945 • Letter: T

Question

The following homework is regarding C++ in unix System

With console logging enabled, write a program that consists of two C++ source files. The first file contains the main() routine and the second file contains a C++ procedure. From within main(), you must display the count of command line arguments to stdout. Further, you must display the value of each command line argument to stdout. Finally, you must call the procedure that is defined in the second file. From within the procedure defined in the second file, you must display a log message that states you are inside the procedure. This log message must be sent to stderr.

Example Output

$> compile.sh

Setting TEMPDIR environment variable to /scratch Compiling file1.cc

Compiling file12.cc

Linking files to create executable hw1

Done

$> run.sh

Running 'hw1' with 0 arguments:

stdout appended to stdout.txt

stderr appended to stderr.txt

Running 'hw1' with 1 argument:

stdout appended to stdout.txt

stderr appended to stderr.txt

Running 'hw1' with 5 arguments:

stdout appended to stdout.txt

stderr appended to stderr.txt

$> more stdout.txt


argc was: 1
./hw1
Done!
argc was: 2
./hw1
abc
Done!
argc was: 6
./hw1
a
b
c
d
e
Done!


$> more stderr.txt
Inside proc1() as stderr
Inside proc1() as stderr
Inside proc1() as stderr

Explanation / Answer

// main file

#include <iostream.h>
#include <proced.cpp>

using namespace std;
int main(int argc, char *argv[])
{
   int i;
   cout<<"The count of the command line arguments is "<<argc<<" ";
   for(i=0;i<argc;i++)
   {
       cout<<i<<"th argument is "<<argv[i]<<" ";
   }
   log_mes();
}


//procedure file
#include<iostream.h>
#include<fstream.h>
void log_mess()
{
   cerr << "Inside the procedure log_mess() ";
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote