Sign In
Not register? Register Now!
You are here: HomeCourseworkIT & Computer Science
Pages:
2 pages/≈550 words
Sources:
2 Sources
Level:
APA
Subject:
IT & Computer Science
Type:
Coursework
Language:
English (U.S.)
Document:
MS Word
Date:
Total cost:
$ 12.96
Topic:

Error Identification and Debugging (Coursework Sample)

Instructions:

Subject: Object oriented programming using c++
Number of words: 550
Number of sources: 3
Formatting style: APA/harvard
Answer the following questions:
q1) The following code causes some compilation errors. Find them and correct them.
// this code contains errors
#include
class A {
A() {
std::cout << "constructing object of class A" << std::endl;
}
~A() {
std::cout << "destroying object of class A" << std::endl;
}
setDatum(int i) {
theDatum = i;
}
getDatum(void) {
return theDatum;
}
private:
int theDatum;
}
int main(int argc, char** argv) {
A a;
a.SetDatum(5);
std::cout << a.GetDatum() << std::endl;
return;
}
What is the corrected program output when executed with fbox{ t ./debug2} ?
Q2. Write a program that prints its own (executable) file size in bytes and in number of printable characters (a character char c is printable if (isalnum(c) > 0 || ispunct(c) > 0 || isspace(c) > 0)).
Q3. Write a program that prints the name of the image files referenced in the web page http://www.enseignement.polytechnique.fr/index.html. Image files are referenced in HTML both by the attribute HREF of the tag A (e.g. ) and by the attribute SRC of the tag IMG (e.g. ). The output should be as follows.
images/entete1.gif
images/remise.gif
images/amphi.gif
/icones/home.gif.
NB: include screenshots of your working

source..
Content:


Object Oriented Programing Assignment
Author’s Name
Institutional Affiliations
Date
left74612500Q1. The following code causes some compilation errors. Find them and correct them, What is the corrected program output when executed with ./debug2?
Explanation to Q1 Solution
In the original code, there were several compilation errors. Firstly, the 'include' statement for the header file had incorrect spellings. According to Stroustrup (2013), the header file should be spelled as '#include .' Secondly, the constructors and destructors for class A were missing the 'public' declaration keyword (Stroustrup, 2013). Thirdly, the member functions setDatum() and getDatum() were missing the void keyword before the function name (Stroustrup, 2013). Finally, the return statement in main() was missing a 542925704850return value (Stroustrup, 2013). Figure 1 provides the corrected code.
Figure 1: Corrected code
438150354330Figure 2 shows the program output when executed with ‘./debug2.’
Figure 2: ‘./debug2’ output.
Q2. Write a program that prints its own (executable) file size in bytes and in number of printable characters (a character char c is printable if (isalnum(c) > 0 || ispunct(c) > 0 || isspace(c) > 0)).
Explanation to Q2 Solution
370840276796500The required program had to read from its executable file (debug2) and count the number of bytes in the file and the number of printable characters. Thus, the std::ios::binary flag counted the number of bytes when opening the file, and then the std::ifstream::tellg function determined the current position of the input stream, which corresponds to the number of bytes in the file (Stroustrup, 2013). A loop that reads each character from the input stream counted the number of printable characters before the std::isalnum, std::ispunct, and std::isspace functions were used to determine whether the character was printable (Stroustrup, 2013). Figure three shows the described C++ program.
Figure 3: A program that prints its own (executable) file size in bytes and in number of printable characters (a character char c is printable if (isalnum(c) > 0 || ispunct(c) > 0 || isspace(c) > 0)).
According to Stroustrup (2013), and as presented in figure 3, the program used the C++ standard library ifstream to open the current executable file in binary mode. It then used the seekg() function to move the file position indicator to the end of the file and the tellg() to determine the file size in bytes stored in the variable. Then, it used seekg() again to move the file position indicator to the beginning of the file. The program reads each file character using the while loop and the get() function. The program used the get() function to read each file character sequentially (Stroustrup, 2013). Inside the while loop, it checked whether the character reading was a printable character or not using the isalnum(), ispunct(), and isspace() functions. These functions returned a non-zero value when the passed character was alphanumeric, punctuation, or whitespace. Whenever the character was printable, the program increased the initial count of printable characters by 1. After the while loop, the program printed the number of printable characters in the file.
Q3. Write a program that prints the name of the image files referenced in the web page http://www.enseignement.polytechnique.fr/index.html.

...
Get the Whole Paper!
Not exactly what you need?
Do you need a custom essay? Order right now:

Other Topics:

  • Cybersecurity
    Description: Cybersecurity IT & Computer Science Coursework...
    6 pages/≈1650 words| 7 Sources | APA | IT & Computer Science | Coursework |
  • Challenges in Identifying and Documenting IT Acquisition Requirements
    Description: Challenges in Identifying and Documenting IT Acquisition Requirements IT & Computer Science Coursework...
    8 pages/≈2200 words| 3 Sources | APA | IT & Computer Science | Coursework |
  • Heuristic Principles Reflection
    Description: The knowledge and skills obtained from this course are vital because it plays an instrumental role in enabling me to fulfill my duties as a data engineer. As a data engineer, the main goal is to make data accessible so that a particular form can utilize it to maximize its performance. As a data engineer ...
    1 page/≈550 words| 2 Sources | APA | IT & Computer Science | Coursework |
Need a Custom Essay Written?
First time 15% Discount!