authorimg

Troubleshooting Compilation Errors and Corrected Program Output

Elina

5.0

Here is Your Sample Download Sample πŸ“©

The following code causes some compilation errors. Find them and correct them

What is the corrected program output when executed with  ./debug2 ?

In the above code, there was some compile time error (Stroustrup, 2015). The rectified code and rectification related comments are shown in the following:

// this code contains errors

#include

using namespace std;

class A {// data member is added initially

     private int theDatum;

     //public access specifier is added

     public:A(){

           std::cout << "constructing object of class A" << std::endl }

     ~A(){std::cout << "destroying object of class A" << std::endl;}

     // return type void is added

     void setDatum(int i) {

           theDatum = i; }

     // return type int is added

     int getDatum(void) {

           return theDatum;}

}; //class closing ';' was missin

int main(int arge, char** argv) {A a;

     // function name corrected

     a.setDatum(5) ;

     // function name corrected

     std::cout << a.getDatum() << std::endl;

     // return value 0

     return 0

After the error rectification, code will run smoothly and its output is shown in the following:

Write a program that prints its own file size in bytes and in number of printable characters 

This following C code reads own binary file and print its size in bytes and also print the number of printable characters present in the file (Kernighan & Ritchie, 2010).

This file considers the args[0] present in the main function as the name of the binary file.

#include

#include

#include

int main(int argc, char ** argv)

{long int size;int temp, count=0;

    char c;char *buffer;

  /* print the binary file name areset as argv[0] */

    printf("\n\nExecutable file name=%s\n", argv[0]);

    /*read the argv[0] executable file*/

    FILE* fp = fopen(argv[0], "rb");

    /*get fseak on the file pointer*/

    fseek(fp, 0L, SEEK_END);

    // get the length of the file using ftell

    size = ftell(fp);

    // print the size

    printf("Size=%ld bytes\n", size)

    /*rewind to start of the file to get character count*/

    rewind(fp);

    /*loop for all char in the file untill EOF*/

    while ((temp = fgetc(fp)) != EOF) {

    /*store current char at c*/

        c = (char)temp;

        /*if c is readable charater, incriment count*/

        if (isalnum(c) > 0 || ispunct(c) > 0 || isspace(c) > 0){

           count++; 

    /*print count*/

    printf("Number of printable characters=%d\n\n",count);

    return 0;}

The program output is shown in the following:

 Write a program that prints the name of the image files referenced in the the web page . Image files are referenced in HTML both by the attribute HREF of the tag The output should be as follows.

To solve this problem, Python web scrapping is used. The implementation work mainly based on the BeautifulSoup library of the Python 3.8 (Thomas & Mathur, 2019).

Note: The given testing URL is not in operation, it redirect to a separate website. So the testing process has been done on the official website of nerdyturtlez 

The python-based web-scrapping code is shown in the following

from bs4 import BeautifulSoup
import requests
# create text representation of the get result
source = requests.get('https://nerdyturtlez.com/').text
# parse the GET result text
soup = BeautifulSoup(source,  "html.parser")
# get all the img tag
images = soup.findAll('img')
# loop for all images
for image in images:
    # print the src
    
print(image['src'])

References

Kernighan, B.W. and Ritchie, D.M. (2010) The C programming language. Englewood Cliffs, NJ: Prentice Hall.

Stroustrup, B. (2015) Programming: Principles and practice using C++. Upper Saddle River (New Jersey), LA: Addison-Wesley.

Thomas, D.M. and Mathur, S. (2019) “Data analysis by web scraping using Python,” 2019 3rd International conference on Electronics, Communication and Aerospace Technology (ICECA) [Preprint]. A