Breaking News

CS102: Introduction to Computer Science II Certification Exam Answers

Introduction to Computer Science II builds upon the foundational concepts introduced in Introduction to Computer Science I. This course delves deeper into programming principles, data structures, algorithms, and software development methodologies. Here’s an overview of what students typically learn in this course:

  1. Advanced Programming Concepts: Building upon basic programming skills, students learn about more advanced programming constructs such as recursion, dynamic memory allocation, file I/O, exception handling, and multi-threading. They gain a deeper understanding of object-oriented programming (OOP) concepts like inheritance, polymorphism, encapsulation, and abstraction.
  2. Data Structures: Students study various data structures such as arrays, linked lists, stacks, queues, trees, graphs, and hash tables. They learn how to implement these data structures, analyze their performance, and choose the appropriate data structure for different scenarios based on time and space complexity considerations.
  3. Algorithms: Students explore fundamental algorithms and algorithmic techniques including sorting, searching, graph traversal, dynamic programming, greedy algorithms, and divide-and-conquer strategies. They analyze the efficiency of algorithms using Big O notation and understand their applications in solving computational problems.
  4. Software Development Practices: This course emphasizes good software engineering practices such as modular design, code reusability, documentation, version control, testing, debugging, and software maintenance. Students learn to write clean, efficient, and maintainable code while adhering to industry standards and best practices.
  5. Object-Oriented Design: Building upon their understanding of OOP concepts, students learn about software design principles like SOLID (Single Responsibility, Open/Closed, Liskov Substitution, Interface Segregation, Dependency Inversion), design patterns (e.g., Factory, Singleton, Observer, Strategy), and architectural patterns (e.g., MVC – Model View Controller). They apply these principles and patterns to design and implement complex software systems.
  6. Introduction to Databases: Students are introduced to database concepts such as relational databases, SQL (Structured Query Language), database normalization, indexing, transactions, and database management systems (DBMS). They learn how to design and interact with databases to store, retrieve, update, and manipulate data efficiently.
  7. Software Development Lifecycle: Students gain an understanding of the software development lifecycle phases including requirements analysis, design, implementation, testing, deployment, and maintenance. They learn about different development methodologies such as waterfall, agile, and iterative approaches, and their pros and cons.
  8. Ethical and Social Implications: Throughout the course, students are encouraged to consider the ethical and social implications of computing, including issues related to privacy, security, intellectual property, accessibility, and the impact of technology on society.

Overall, Introduction to Computer Science II aims to equip students with the knowledge, skills, and mindset required to tackle more complex programming challenges, design scalable software solutions, and contribute effectively to the field of computer science and software engineering.

CS102: Introduction to Computer Science II Exam Quiz Answers

CS102 Introduction to Computer Science II
  • They have vastly superior compilers that create machine code that saves time and memory
  • They provide libraries of functions, like C++’s Standard Template Library or Java’s Container Library
  • They offer documentation tools that explain algorithms in more human-oriented, understandable ways
  • They focus on problem spaces and do not constrain programmers to specific problem-solving approaches
  • They have states, behavior, unique identities, and can communicate with other entities
  • They have states, behavior, unique identities, and can communicate with other entities
  • They are well-commented blocks of code that can be easily replaced and modified as the need arises
  • They provide reusable code for common functionality and can be called from other program components
  • Classes, objects, iterators
  • Subroutines, functions, methods
  • Sequence of instructions, choose which instructions, repeat a block of instructions
  • Problem statement, abstraction of the problem, implementation of the problem solution
  • Messaging, remote-call, independent, thread, reuse, mutex
  • Call, procedure, process, do-while, if-then-else, loop, function
  • Class, method, attribute, polymorphism, inheritance, instance
  • Lock, unlock, delete, garbage cleanup, orphaned memory, pointer
  • Solutions are defined in terms of classes; classes instantiate as objects; objects are formed into hierarchies by generalizing or specializing; objects can communicate with other objects
  • Trusted reusable software functions and subroutines are formed into libraries that enable programmers to focus on the increasing complexity of modern-day problems and their solutions
  • Independent software modules exist within a computer network; they do not necessarily share memory; the modules can communicate within various design architectures to enable problem solutions
  • Software projects require using known, good software modules that are a natural part of a computer programming languages that focus on solving problems rather than the programming process
  • Create reusable libraries to save project time in the future
  • Write documentation to make clear which datasets can be employed
  • Design and implement them to be agnostic of data type to give programmers greater flexibility
  • Perform testing to determine if the functionality is superior to code written on a project-by-project basis
  • Whether to use non-local hosting versus using local hosting
  • What things need to be accomplished versus how to accomplish things
  • Creating multi-language systems versus creating same-language systems
  • Implementation in non-shared memory versus implementation in shared memory
  • It enables libraries, which minimizes the amount of new programming needed to solve any given problem
  • It constructs catalogs of useful and efficient algorithms and data structures that are agnostic of data type
  • It produces essential data-flow architectures that act as problem-solving tools for modern, networked problems
  • It does not matter where a function is physically located, since any function can be called as if it were hosted within the program itself
  • #include <iostream>

#include <list>

#include <iterator>

using namespace std;

int main()

{

list <string> stringList;

list <string> ::iterator it;

stringList.push_back(“Dog”);

stringList.push_back(“Cat”);

stringList.push_back(“Horse”);

stringList.push_back(“Chicken”);

int length = stringList.size();

for (int i = 0; i < length; i++)

{

cout << stringList.front() << endl;

stringList.pop_front();

}

return 0;

}

  • #include <iostream>

#include <list>

#include <iterator>

using namespace std;

int main()

{

list <string> stringList;

list <string> ::iterator it;

stringList.push_back(“Dog”);

stringList.push_back(“Cat”);

stringList.push_back(“Horse”);

stringList.push_back(“Chicken”);

while(stringList.size() > 0)

{

cout << stringList.front() << endl;

stringList.pop_front();

}

return 0;

}

  • #include <iostream>

#include <list>

#include <iterator>

using namespace std;

int main()

{

list <string> stringList;

list <string> ::iterator it;

stringList.push_back(“Dog”);

stringList.push_back(“Cat”);

stringList.push_back(“Horse”);

stringList.push_back(“Chicken”);

for (it = stringList.begin(); it != stringList.end(); ++it)

std::cout << *it << endl;

return 0;

}

  • #include <iostream>

#include <list>

#include <iterator>

using namespace std;

int main()

{

list <string> stringList;

list <string> ::iterator it;

stringList.push_back(“Dog”);

stringList.push_back(“Cat”);

stringList.push_back(“Horse”);

stringList.push_back(“Chicken”);

int length = stringList.size();

for (int i = length; i >= 1; i–)

{

cout << stringList.front() << endl;

stringList.pop_front();

}

return 0;

}

  • package com.company;

public class Main

{

    public static void main(String[] args)

    {

        Map<String, Integer> eventMap =

          new HashMap<String, Integer>();

        String thisEvent;

        Integer count;

        boolean keyPresent;

        for (int i = 0; i < 100; i++)

          for (Integer e = 0; e <= 127; e++)

        {

            thisEvent = Integer.toString(e.intValue());

            keyPresent =

              eventMap.containsKey(thisEvent);

            if( ! keyPresent ) eventMap.put(thisEvent, 0);

            else

            {

                count = eventMap.get(thisEvent);

                eventMap.put(thisEvent, count + 1);

            }

        }

        thisEvent = “2”;

        count = eventMap.get(thisEvent);

        System.out.println(“Example: ” + thisEvent +

          ” ” + Integer.toString(count.intValue()));

    }

}           #include <iostream>

#include <map>

#include <string>

int main()

{

  map<string, unsigned int> eventMap;

  map<string, unsigned int>::iterator

     eventMapPointer;

  string thisEvent;

  for (int i = 0; i < 100; i++)

    for (unsigned int e = 0; e <= 127; e++)

  {

    thisEvent = (char)e;

    eventMapPointer = eventMap.find(thisEvent);

    if (eventMapPointer == eventMap.end())

      eventMap[thisEvent] = 0;

    else (*eventMapPointer).second++;

  }

  eventMapPointer = eventMap.find(“2”);

  cout << “Example: ” << (*eventMapPointer).first <<

     ‘ ‘ << (*eventMapPointer).second << endl;

  return 0;

}

  • package com.company;

import java.util.*;

public class Main

{

    public static void main(String[] args)

    {

        Map<String, Integer> eventMap =

          new HashMap<String, Integer>();

        String thisEvent;

        Integer count;

        boolean keyPresent;

        for (int i = 0; i < 100; i++)

          for (Integer e = 0; e <= 127; e++)

        {

            thisEvent = Integer.toString(e.intValue());

            keyPresent =

              eventMap.containsKey(thisEvent);

            if( ! keyPresent ) eventMap.put(thisEvent, 0);

            else

            {

                count = eventMap.get(thisEvent);

                eventMap.put(thisEvent, count + 1);

            }

            thisEvent = “2”;

            count = eventMap.get(thisEvent);

            System.out.println(“Example: ” + thisEvent +

               ” ” + Integer.toString(count.intValue()));

        }

    }

}           #include <iostream>

#include <map>

#include <string>

using namespace std;

int main()

{

  map<string, unsigned int> eventMap;

  map<string, unsigned int>::iterator

     eventMapPointer;

  string thisEvent;

  for (int i = 0; i < 100; i++)

    for (unsigned int e = 0; e <= 127; e++)

  {

    thisEvent = (char)e;

    eventMapPointer = eventMap.find(thisEvent);

    if (eventMapPointer == eventMap.end())

      eventMap[thisEvent] = 0;

    else (*eventMapPointer).second++;

    eventMapPointer = eventMap.find(“2”);

    cout << “Example: ” << (*eventMapPointer).first <<

       ‘ ‘ << (*eventMapPointer).second << endl;

  }

  return 0;

}

  • package com.company;

import java.util.*;

public class Main

{

    public static void main(String[] args)

    {

        Map<String, Integer> eventMap =

          new HashMap<String, Integer>();

        String thisEvent;

        Integer count;

        boolean keyPresent;

        for (int i = 0; i < 100; i++)

          for (Integer e = 0; e <= 127; e++)

        {

            thisEvent = Integer.toString(e.intValue());

            keyPresent =

              eventMap.containsKey(thisEvent);

            if( ! keyPresent ) eventMap.put(thisEvent, 0);

            else

            {

                count = eventMap.get(thisEvent);

                eventMap.put(thisEvent, count + 1);

            }

        }

        thisEvent = “2”;

        count = eventMap.get(thisEvent);

        System.out.println(“Example: ” + thisEvent +

          ” ” + Integer.toString(count.intValue()));

    }

}           #include <iostream>

#include <map>

#include <string>

using namespace std;

int main()

{

  map<string, unsigned int> eventMap;

  map<string, unsigned int>::iterator

     eventMapPointer;

  string thisEvent;

  for (int i = 0; i < 100; i++)

    for (unsigned int e = 0; e <= 127; e++)

  {

    thisEvent = (char)e;

    eventMapPointer = eventMap.find(thisEvent);

    if (eventMapPointer == eventMap.end())

      eventMap[thisEvent] = 0;

    else (*eventMapPointer).second++;

  }

  eventMapPointer = eventMap.find(“2”);

  cout << “Example: ” << (*eventMapPointer).first <<

     ‘ ‘ << (*eventMapPointer).second << endl;

  return 0;

}

  • package com.company;

import java.util.*;

public class Main

{

    public static void main(String[] args)

    {

        Map<String, Integer> eventMap =

          new HashMap<String, Integer>();

        String thisEvent;

        Integer count;

        for (int i = 0; i < 100; i++)

          for (Integer e = 0; e <= 127; e++)

        {

            thisEvent = Integer.toString(e.intValue());

            count =

              eventMap.get(thisEvent);

            if(count != null) eventMap.put(thisEvent, 0);

            else

            {

                 eventMap.put(thisEvent, count + 1);

            }

            thisEvent = “2”;

            count = eventMap.get(thisEvent);

            System.out.println(“Example: ” + thisEvent +

               ” ” + Integer.toString(count.intValue()));

        }

    }

}           #include <iostream>

#include <map>

#include <string>

using namespace std;

int main()

{

  map<string, unsigned int> eventMap;

  map<string, unsigned int>::iterator

     eventMapPointer;

  string thisEvent;

  for (int i = 0; i < 100; i++)

    for (unsigned int e = 0; e <= 127; e++)

  {

    thisEvent = (char)e;

    eventMapPointer = eventMap.find(thisEvent);

    if (eventMapPointer != eventMap.end())

      eventMap[thisEvent] = 0;

    else (*eventMapPointer).second++;

    eventMapPointer = eventMap.find(“2”);

    cout << “Example: ” << (*eventMapPointer).first <<

       ‘ ‘ << (*eventMapPointer).second << endl;

  }

  return 0;

}

  • package com.company;

public class Main

{

    final static class MyThread extends Thread

    {

        public void run()

        {

            System.out.println(“MyThread running”);

        }

    }

    public static void main(String[] args)

       throws InterruptedException

    {

        MyThread myThread = new MyThread();

        myThread.run();

        myThread.join();

        System.out.println(“myThread Completed”);

    }

}           #include <iostream>

#include <thread>

using namespace std;

void MyThread()

{

  cout << “MyThread running” << endl;

}

int main()

{

  thread myThread (MyThread);

  myThread.run();

  myThread.join();

  cout << “myThread Completed\n”;

  return 0;

}

  • package com.company;

public class Main

{

    final static class MyThread extends Thread

    {

        public void run()

        {

            System.out.println(“MyThread running”);

        }

    }

    public static void main(String[] args)

       throws InterruptedException

    {

        MyThread myThread = new MyThread();

        myThread.start();

        myThread.join();

        System.out.println(“myThread Completed”);

    }

}                       #include <iostream>

#include <thread>

using namespace std;

void MyThread()

{

  cout << “MyThread running” << endl;

}

int main()

{

  thread myThread (MyThread);

  myThread.join();

  cout << “myThread Completed\n”;

  return 0;

}

  • package com.company;

public class Main

{

    final static class MyThread extends Thread

    {

        public void run()

        {

            System.out.println(“MyThread running”);

        }

    }

    public static void main(String[] args)

       throws InterruptedException

    {

        MyThread myThread = new MyThread();

        myThread.join();

        System.out.println(“myThread Completed”);

    }

}           #include <iostream>

#include <thread>

using namespace std;

void MyThread()

{

  cout << “MyThread running” << endl;

}

int main()

{

  thread myThread (MyThread);

  myThread.start();

  myThread.join();

  cout << “myThread Completed\n”;

  return 0;

}

  • package com.company;

public class Main

{

    final static class MyThread extends Thread

    {

        public void run()

        {

            System.out.println(“MyThread running”);

        }

    }

    public static void main(String[] args)

       throws InterruptedException

    {

        MyThread myThread = new MyThread();

        myThread.start();

        myThread.join();

        System.out.println(“myThread Completed”);

    }

}                       #include <iostream>

#include <thread>

using namespace std;

void MyThread()

{

  cout << “MyThread running” << endl;

}

int main()

{

  MyThread();

  cout << “myThread Completed\n”;

  return 0;

}

  • C++ is completely unable to interact with processes not written in C++, while Java has the ability to interact with processes written in other languages
  • In C++, pointers, references, and pass-by-value are supported only for primitive data types, while in Java primitive data types are always passed by value
  • In C++, pointers, references, and pass-by-value are supported for all primitive and user-defined data types, while in Java all data types are always passed by value
  • In C++, there is no way at all to access data not resident in the program’s shared memory, while in Java functionality can be created to access data not residing in the program’s shared memory
  • Java does not enable integer variables, only floating-point; C++ enables both integer and floating point
  • Java does not have native floating-point variables; C++ has several different floating point variable types
  • Java does not support native unsigned arithmetic data types; C++ has native unsigned arithmetic support
  • Java supports certain native variable types which have class-based equivalents; C++ is only beginning to implement such capability in beta releases
  • They are both data-type agnostic
  • They are both are written in assembler
  • They are both assembled from public libraries
  • They are both directly interchangeable from one language to another
  • The ability to create directly-executable machine code for any computer platform
  • The freedom from having to consider the details of a given language, especially data-types
  • Robust documentation tools that can be used to make any code completely understandable
  • The ability to easily merge components from any language seamlessly into a single application
  • Well-documented type-specific subroutines and functions, which enables efficient runtime
  • Remote-calling capability that allows for taking advantage of any collection’s or library’s capability
  • Expansion of the C language to include object-orientation as a native programming language feature
  • Expansion of the C language to include object-orientation as a native programming language feature
  • They both collect language-specific public libraries in a common catalog that provides documentation
  • They both result in directly-executable machine code that can be accessed by other language modules
  • Both use the same syntax, which means they are interpretable by either language’s compilation process
  • Both provide language-standard libraries of data structures and functionality that are data-type agnostic
  • #include <iostream>

using namespace std;

typedef struct {string elements [10];} Record, *pRecord;

struct key_value {string first; pRecord second = NULL; key_value *next = NULL; };

pRecord thisRecord = NULL;

key_value *Database = NULL;

key_value* lastEntry = NULL;

void Add_Entry(string key, pRecord thisRecord)

{

if (Database != NULL)

{

lastEntry->next = new key_value;

lastEntry = lastEntry->next;;

}

else

{

Database = new key_value;

lastEntry = Database;   

}

lastEntry->first = key;

lastEntry->second = thisRecord;

}

int main()

{

thisRecord = new Record;

thisRecord->elements[0] = “Step 1”;

Add_Entry(“Study”, thisRecord);

thisRecord = new Record;

thisRecord->elements[0] = “Step 2”;

Add_Entry(“Learn”, thisRecord);

thisRecord = new Record;

thisRecord->elements[0] = “Step 3”;

Add_Entry(“Work”, thisRecord);

thisRecord = new Record;

thisRecord->elements[0] = “Step 4”;

Add_Entry(“Produce”, thisRecord);

thisRecord = new Record;

thisRecord->elements[0] = “Cycle Through Steps”;

Add_Entry(“Repeat”, thisRecord);

key_value* thisEntry = Database;

while (thisEntry != NULL)

{

cout << thisEntry->first << ” : ” << thisEntry->second->elements[0] << endl;

thisEntry = thisEntry->next;

}

}

  • #include <iostream>

#include <unordered_map>

using namespace std;

typedef struct { string elements[10]; } Record, *pRecord;

pRecord thisRecord = NULL;

unordered_map<string, pRecord> Database;

int main()

{

thisRecord = new Record;

thisRecord->elements[0] = “Step 1”;

Database[“Study”] = thisRecord;

thisRecord = new Record;

thisRecord->elements[0] = “Step 2”;

Database[“Learn”] = thisRecord;

thisRecord = new Record;

thisRecord->elements[0] = “Step 3”;

Database[“Work”] = thisRecord;

thisRecord = new Record;

thisRecord->elements[0] = “Step 4”;

Database[“Produce”] = thisRecord;

thisRecord = new Record;

thisRecord->elements[0] = “Cycle Through Steps”;

Database[“Repeat”] = thisRecord;

for (auto key_value : Database)

cout << key_value.first << ” : ” << key_value.second->elements[0] << endl;

}

  • #include 

#include 

using namespace std;

typedef struct { string key;  string elements[10]; } Record, * pRecord;

pRecord thisRecord;

list Database;

int main()

{

thisRecord = new Record;

thisRecord->elements[0] = “Step 1”;

thisRecord->key = “Study”;

Database.push_back(thisRecord);

thisRecord = new Record;

thisRecord->elements[0] = “Step 2”;

thisRecord->key = “Learn”;

Database.push_back(thisRecord);

thisRecord = new Record;

thisRecord->elements[0] = “Step 3”;

thisRecord->key = “Work”;

Database.push_back(thisRecord);

thisRecord = new Record;

thisRecord->elements[0] = “Step 4”;

thisRecord->key = “Produce”;

Database.push_back(thisRecord);

thisRecord = new Record;

thisRecord->elements[0] = “Cycle Through Steps”;

thisRecord->key = “Repeat”;

Database.push_back(thisRecord);

for (auto key_value : Database)

cout << key_value->key << ” : ” << key_value->elements[0] << endl;

}

  • #include <iostream>

#include <set>

using namespace std;

typedef struct { string key;  string elements[10]; } Record, * pRecord;

pRecord thisRecord;

set<pRecord> Database;

int main()

{

thisRecord = new Record;

thisRecord->elements[0] = “Step 1”;

thisRecord->key = “Study”;

Database.insert(thisRecord);

thisRecord = new Record;

thisRecord->elements[0] = “Step 2”;

thisRecord->key = “Learn”;

Database.insert(thisRecord);

thisRecord = new Record;

thisRecord->elements[0] = “Step 3”;

thisRecord->key = “Work”;

Database.insert(thisRecord);

thisRecord = new Record;

thisRecord->elements[0] = “Step 4”;

thisRecord->key = “Produce”;

Database.insert(thisRecord);

thisRecord = new Record;

thisRecord->elements[0] = “Cycle Through Steps”;

thisRecord->key = “Repeat”;

Database.insert(thisRecord);

for (auto key_value : Database)

cout << key_value->key << ” : ” << key_value->elements[0] << endl;

}

  • Data structures that are linear and associative
  • Local and remote hosting of program modules
  • Shared and non-shared memory for storing data structures
  • Compiled/linked and interpreted code for runtime implementation
  • In both Java and C++, collections can only be written to store class objects
  • In both Java and C++, collections are not generic since they can only hold primitive types
  • In Java, any collection can be written to store any class, while collections in C++ can only deal with primitive types
  • In Java, any collection can be written to store any class, while C++ collections hold primitive types in addition to classes
  • Stacks, queues, and arrays
  • Ordered lists, arrays, and vectors
  • Trees, dictionaries/maps, and vectors
  • Ordered lists, dictionaries/maps, and sets
  • To trigger threads when specific program conditions are met
  • To prevent sudden program termination due to abnormal conditions
  • To provide an expanded if/then/else capability that is more expressive
  • To instantiate loops with unusual conditions for ending a cycle of code execution
  • Increases operating system portability, increases hardware portability, and increases language portability
  • Expands the conditions for terminating loops, improves thread control, and provides access other-language components
  • Creates a system of hardware interrupts, expands conditionals, and acts as an alternative to if/then/else logic structures
  • Improves error recovery, eases the creation of robust program components, and minimizes the chance of unrecoverable errors
  • package com.company;

public class Main

{

    public static void main

      (String[] args)

    {

        try { int i = 5 / 0; }

        catch (Exception e)

        {

            System.out.println

              (e.toString());

            e.printStackTrace();

            System.out.println

              (“Program Abended”);

            System.exit(-1);

        }

        System.out.println

          (“Program Ended Normally”);

    }

}                       #include <iostream>

#include <typeinfo>

#include <exception>

using namespace std;

class Polymorphic

{ virtual void Member() {} };

int main()

{

  try

  {

    Polymorphic* pb = 0;

    cout << typeid(*pb).name();

  }

  catch (exception &e)

  {

    cout <<

      “An exception occurred: ” <<

      endl << e.what() << ‘\n’;

    cout <<

      “*** Location: Module Main: ” <<

      Catch Statement: 001″ << endl;

    cout << “Program Abended” << endl;

    return -1;

  }

  cout << “Program Ended Normally” <<

    endl;

  return 0;

}

  • package com.company;

public class Main

{

    public static void main

      (String[] args) throws Exception

    {

        int i = 5 / 0;

        System.out.println

          (“Program Ended Normally”);

    }

}                       #include <iostream>

#include <typeinfo>

#include <exception>

using namespace std;

class Polymorphic

{ virtual void Member() {} };

int main()

{

  Polymorphic* pb = 0;

  cout << typeid(*pb).name();

  cout << “Program Ended Normally” <<

    endl;

  return 0;

}

  • package com.company;

public class Main

{

    public static void main

      (String[] args)

    {

        try { int i = 5 / 0; }

        catch (Exception e) { }

        System.out.println

          (“Program Ended Normally”);

    }

}                       #include <iostream>

#include <typeinfo>

#include <exception>

using namespace std;

class Polymorphic

{ virtual void Member() {} };

int main()

{

  try

  {

    Polymorphic* pb = 0;

    cout << typeid(*pb).name();

  }

  catch (…) { }

  cout << “Program Ended Normally” <<

    endl;

  return 0;

}

  • package com.company;

public class Main

{

    public static void main

      (String[] args)

    {

        try { int i = 5 / 0; }

        catch (Exception e)

        {

            System.out.println

              (“Caught an Exception);

        }

        System.out.println

          (“Program Ended Normally”);

    }

}                       #include <iostream>

#include <typeinfo>

#include <exception>

using namespace std;

class Polymorphic

{ virtual void Member() {} };

int main()

{

  try

  {

    Polymorphic* pb = 0;

    cout << typeid(*pb).name();

  }

  catch (exception &e)

  {

    cout <<

      “An exception occurred.” <<

      endl;

  }

  cout << “Program Ended Normally” <<

    endl;

  return 0;

}

  • package com.company;

class Exception_NullInteger

{

    public String feedback;

    public Integer newValue;

    Exception_NullInteger(String feedback, Integer I)

    {

        // some processing on constructor input values

        I = 0; // result of that processing

        this.newValue = I;

        this.feedback = feedback;

    }

}

public class Main

{

    public static void main(String[] args)

    {

        Integer I = null;

        Exception_NullInteger myException = null;

        try { System.out.println(I.toString()); }

        catch (Exception_NullInteger e)

        {

            System.out.println(e.toString());

            System.out.println(e.feedback);

            I = e.newValue;

            System.out.println(“Value confirmed to be ” + I.toString());

            System.out.println(“StackTrace: “);

            StackTraceElement[] thisStackTrace = e.getStackTrace();

            for (int L = 0; L < thisStackTrace.length; L++)

                System.out.println(“\t” + thisStackTrace[L].toString());

        }

        finally { System.out.println(“Main Continues”); }

    }

}

  • package com.company;

class Exception_NullInteger extends Exception

{

    public String feedback;

    public Integer newValue;

    Exception_NullInteger(String feedback, Integer I)

    {

        // some processing on constructor input values

        I = 0; // result of that processing

        this.newValue = I;

        this.feedback = feedback;

    }

}

public class Main

{

    public static void main(String[] args)

    {

        Integer I = null;

        Exception_NullInteger myException = null;

        try { System.out.println(I.toString()); }

        catch (NullPointerException e)

        {

            System.out.println(e.toString());

            System.out.println(“StackTrace: “);

            StackTraceElement[] thisStackTrace = e.getStackTrace();

            for (int L = 0; L < thisStackTrace.length; L++)

                System.out.println(“\t” + thisStackTrace[L].toString());

        }

        finally { System.out.println(“Main Continues”); }

    }

}

  • package com.company;

class Exception_NullInteger extends Exception

{

    public String feedback;

    public Integer newValue;

    Exception_NullInteger(String feedback, Integer I)

    {

        // some processing on constructor input values

        I = 0; // result of that processing

        this.newValue = I;

        this.feedback = feedback;

    }

}

public class Main

{

    public static void main(String[] args)

    {

        Integer I = null;

        Exception_NullInteger myException = null;

        try

        {

            if (I == null)

               throw new Exception_NullInteger(“Exception: Integer is null.”, I);

        }

        catch (Exception_NullInteger e)

        {

            System.out.println(e.toString());

            System.out.println(e.feedback);

            I = e.newValue;

            System.out.println(“Value confirmed to be ” + I.toString());

            System.out.println(“StackTrace: “);

            StackTraceElement[] thisStackTrace = e.getStackTrace();

            for (int L = 0; L < thisStackTrace.length; L++)

                System.out.println(“\t” + thisStackTrace[L].toString());

        }

        finally { System.out.println(“Main Continues”); }

    }

}

  • package com.company;

class Exception_NullInteger extends Exception

{

    public String feedback;

    public Integer newValue;

    Exception_NullInteger(String feedback, Integer I)

    {

        // some processing on constructor input values

        I = 0; // result of that processing

        this.newValue = I;

        this.feedback = feedback;

    }

}

public class Main

{

    public static void main(String[] args)

    {

        Integer I = null;

        Exception_NullInteger myException = null;

        if (I == null)

        {

            I = 0;

            System.out.println(“Value confirmed to be ” + I.toString());

        }

        System.out.println(“Main Continues”);

    }

}

  • #include <iostream>

using namespace std;

int main()

{

  while (true)

  {

    try

    {

      char* c = new char[9999999];

    }

    catch (bad_alloc &e)

    {

      cout << “*** Out of memory at Point A.” << endl;

      cout << e.what() << endl;

      cout << “Program Abended.” << endl;

      return -1;

    }

  }

  cout << “Program Ended Normally.” << endl;

  return 0;

}

  • #include <iostream>

using namespace std;

int main()

{

  while (true)

  {

    char* c = new char[9999999];

    if (c == NULL) cout << “Out of memory” << endl;

  }

  return 0;

}

  • #include <iostream>

using namespace std;

int main()

{

  char* c = NULL;

  while (true)

  {

    try

    {

      c = new char[9999999];

    }

    catch (bad_alloc &e)

    {

      cout << e.what() << ”  Point A.” << endl;

      c = new char[9999999];

    }

  }

  cout << “Program Ended Normally.” << endl;

  return 0;

}

  • using namespace std;

int main()

{

  while (true)

  {

    try

    {

      char* c = new char[9999999];

    }

    catch (bad_alloc &e)

    {

      c = NULL;

    }

  }

  cout << “Program Ended Normally.” << endl;

  return 0;

}

  • #include <iostream>

#include <thread>

#include <list>

using namespace std;

#define length 9999

void anotherThread(int n)

{

  char thisCharSeq[length];

  while (true) { int i = n; }

}

int main()

{

  list<thread> theseThreads;

  int n = 0;

  while (true)

  {

    theseThreads.push_back(thread(anotherThread, ++n));

  }

  std::cout << “Program Ended Normally.\n”;

  return 0;

}

  • #include <iostream>

#include <thread>

#include <list>

using namespace std;

#define length 9999

void anotherThread(int n)

{

  char thisCharSeq[length];

  while (true) { int i = n; }

}

int main()

{

  list<thread> theseThreads;

  int n = 0;

  while (true)

  {

    try

    {

      theseThreads.push_back(thread(anotherThread, ++n));

    }

    catch (exception& e)

    {

      cout << “Exception: Point A.” << endl;

      cout << “Thread Count: ” << n << endl;

      cout << e.what() << endl;

      cout << “Program Abended.” << endl;

      return -1;

    }

  }

  std::cout << “Program Ended Normally.\n”;

  return 0;

}

  • #include <iostream>

#include <thread>

#include <list>

using namespace std;

#define length 9999

void anotherThread(int n)

{

  char thisCharSeq[length];

  while (true) { int i = n; }

}

int main()

{

  list<thread> theseThreads;

  int n = 0;

  while (true)

  {

    try

    {

      theseThreads.push_back(thread(anotherThread, ++n));

    }

    catch (…) {}

  }

  std::cout << “Program Ended Normally.\n”;

  return 0;

}

  • #include <iostream>

#include <thread>

#include <list>

using namespace std;

#define length 9999

void anotherThread(int n)

{

  char thisCharSeq[length];

  while (true) { int i = n; }

}

int main()

{

  list<thread> theseThreads;

  int n = 0;

  while (true)

  {

    try

    {

      theseThreads.push_back(thread(anotherThread, ++n));

    }

    catch (stack_overflow& e)

    {

      cout << “Exception: Point A.” << endl;

      cout << “Thread Count: ” << n << endl;

      cout << e.what() << endl;

      cout << “Program Abended.” << endl;

      return -1;

    }

  }

  std::cout << “Program Ended Normally.\n”;

  return 0;

}

  • They use the results of multiple independent processes to build and populate data structures. Analyzing them enables objective conclusions to be reached about complex problems. They are serendipitous and only possible in large networked systems.
  • They reduce a complex problem into simpler problems, and combine those problems to form the solution to a complex problem. They are composed of a base case (where a direct solution exists) and an inductive case (where additional reduction is required).
  • They spawn threads to handle components of an extensive calculation or data manipulation so that time-to-completion is reduced. They combine the threads’ results to form the overall solution. They can also be created via processes in non-shared memory running on geographically-dispersed computers.
  • They combine solutions to random simpler problems to provide insight into more-complex problems. The solution to simpler problems leads to solutions of problems at a higher and higher level of generality. They can then be used to provide solutions to different specific cases than the ones originally encountered.
  1. Pick one element of the list to be the “pivot element”.
  2. Break the list one list of elements less than the pivot element, and one of elements greater than the pivot element.
  3. Sort each of the smaller lists recursively.
  4. Make one big list: the list of items smaller than the pivot element, then the pivot element, and then the list of elements bigger than the pivot element.
  • #include <iostream>

using namespace std;

const int arraySize = 6;

int Partition_ChosePivot(double (&A)[arraySize], int beginRange, int endRange)

{

  double hold;

  double pivot = A[beginRange];

  int left = beginRange;

  for (int i = beginRange + 1; i <= endRange; i++)

  {

    if (A[i] < pivot)

    {

      left++;

      hold = A[i];

      A[i] = A[left];

      A[left] = hold;

    }

  }

  return left;

}

void QUICKSORT(double (&A)[arraySize], int beginRange, int endRange)

{

  if (beginRange < endRange)

  {

    int pivot = Partition_ChosePivot(A, beginRange, endRange);

    QUICKSORT(A, beginRange, pivot – 1);

    QUICKSORT(A, pivot + 1, endRange);

  }

}

int main()

{

  double array[arraySize] = { 20, 2, 0, 1, 1, 10 };

  QUICKSORT(array, 0, arraySize – 1);

  for(int i = 0; i < arraySize; i++) cout << array[i] << “\n”;

  return 0;

}

  • #include <iostream>

using namespace std;

const int arraySize = 6;

int Partition_ChosePivot(double (&A)[arraySize], int beginRange, int endRange)

{

  double hold;

  double pivot = A[beginRange];

  int left = beginRange;

  for (int i = beginRange + 1; i <= endRange; i++)

  {

    if (A[i] < pivot)

    {

      left++;

      hold = A[i];

      A[i] = A[left];

      A[left] = hold;

    }

  }

  hold = A[beginRange];

  A[beginRange] = A[left];

  A[left] = hold;

  return left;

}

void QUICKSORT(double (&A)[arraySize], int beginRange, int endRange)

{

  if (beginRange < endRange)

  {

    int pivot = Partition_ChosePivot(A, beginRange, endRange);

    QUICKSORT(A, beginRange, pivot – 1);

  }

}

int main()

{

  double array[arraySize] = { 20, 2, 0, 1, 1, 10 };

  QUICKSORT(array, 0, arraySize – 1);

  for(int i = 0; i < arraySize; i++) cout << array[i] << “\n”;

  return 0;

}

  • #include <iostream>

using namespace std;

const int arraySize = 6;

int Partition_ChoosePivot(double (&A)[arraySize], int beginRange, int endRange)

{

double hold;

double pivot = A[beginRange];

int left = beginRange;

for (int i = beginRange + 1; i <= endRange; i++)

{

if (A[i] < pivot)

{

left++;

hold = A[i];

A[i] = A[left];

A[left] = hold;

}

}

hold = A[beginRange];

A[beginRange] = A[left];

A[left] = hold;

return left;

}

void QUICKSORT(double (&A)[arraySize], int beginRange, int endRange)

{

if (beginRange < endRange)

{

int pivot = Partition_ChoosePivot(A, beginRange, endRange);

QUICKSORT(A, beginRange, pivot – 1);

QUICKSORT(A, pivot + 1, endRange);

}

}

int main()

{

double array[arraySize] = { 20, 2, 0, 1, 1, 10 };

QUICKSORT(array, 0, arraySize – 1);

for(int i = 0; i < arraySize; i++) cout << array[i] << “\n”;

return 0;

}

  • #include <iostream>

using namespace std;

const int arraySize = 6;

int Partition_ChosePivot(double (&A)[arraySize], int beginRange, int endRange)

{

  double hold;

  double pivot = A[beginRange];

  int left = beginRange;

  for (int i = beginRange + 1; i <= endRange; i++)

  {

    if (A[i] < pivot)

    {

      left++;

      hold = A[i];

      A[i] = A[left];

      A[left] = hold;

    }

  }

  hold = A[beginRange];

  A[beginRange] = A[left];

  A[left] = hold;

  return left;

}

void QUICKSORT(double (&A)[arraySize], int beginRange, int endRange)

{

  if (beginRange < endRange)

  {

    int pivot = Partition_ChosePivot(A, beginRange, endRange);

    QUICKSORT(A, beginRange, pivot – 1);

    QUICKSORT(A, pivot + 1, endRange);

  }

}

int main()

{

  double array[arraySize] = { 20, 2, 0, 1, 1, 10 };

  int pivot = 3;

  QUICKSORT(array, pivot, arraySize – 1);

  for(int i = 0; i < arraySize; i++) cout << array[i] << “\n”;

  return 0;

}

  • Using only one language rather than mixed languages
  • Being able to self-implement rather than using established modules
  • The average complexity of both time and memory for the expected data sizes
  • Implementing so that as few machine or byte codes are executed during runtime as possible
  • Yes: any calculation expressed in mathematics can be expressed in the target computer language; the code simply has to be written and tested
  • Yes: many modern languages in computer science contain the syntax to exactly translate the notation of mathematics into the notation of the language in question
  • No: many modern languages in computer science are incapable of recursive operation; instead, recursive mathematics must be translated into non-recursive (explicit/iterative) procedures
  • No: mathematics rests on the infinity theory, while computer science depends on finite machines; computers can realistically represent numbers of only limited size and accuracy, even with special software
  • List search and sort cannot be implemented as in-pace algorithms
  • Lists have only one link from one data-element’s memory to another
  • Data organized for list search and sort often occupies contiguous memory
  • List search and sort generally require twice the amount of memory as occupied by the dataset
CS-102-Introduction-to-Computer-Science-II-Answer-Key-Saylor-Academy
  • Depth-first
  • Breadth-first
  • Sequential memory locations
  • Either row-first or column-first
  • Count the number of lines in the pre-compiled source code, and add a factor for loops
  • Count the number of assembler tokens or byte codes generated from the source code
  • Count lines of executable code, run timing experiments, and add time for sorting data
  • Add a multiplier for each memory access required during operations when the language requires it
CS 102 Introduction to Computer Science II Answer Key Saylor Academy 2
  • The algorithm in red is always better
  • The algorithm in blue is always better
  • Either algorithm works when there is sufficient memory
  • The algorithm in blue is better for datasets of size 45 or less
  • From functional, to modular, to object-oriented
  • From abstractions of the computer to abstractions of the problem to be solved
  • From binary, to assembler, to imperative languages, to higher-level languages
  • From large volumes of hard-to-read code to smaller volumes of easy-to-read code
  • It became more common to use reusable trusted code instead of writing everything from scratch
  • The classes within object-oriented programming languages started to be seen as new data types
  • They evolved from personal and open-access programming libraries to language-standard libraries
  • They evolved from type-specific functions and subroutines to type-inspecific functions and subroutines
  • They enable visiting all elements of a data structure without regard for the type of a structure’s elements
  • They point to generic data elements regardless of their physical location; they are host-location agnostic
  • They are a direct replacement for the index of for loops; one simply defines the iterator type appropriately
  • They reference all duplicative records within main and backup databases, they are record-length agnostic
  • Both C++ and Java go through a compile-then-link process that produces machine code that runs directly on the compute
  • Both C++ and Java generate pseudo-code that is interpreted by a separate low-level program that is written specifically for a given type of CPU
  • The C++ compiler creates bytecodes that are interpreted by an operating system process, while the Java compiler creates machine language, and a linker ties code modules together into a directly-executable program
  • C++ uses a compiler to create machine language and a linker to tie code modules together into a directly-executable program, while Java’s compiler creates bytecodes that are interpreted by the Java Virtual Machine
  • C++ has an embedded library of functionality that is part of the language standard, while Java requires the use of third-party libraries if one wishes to employ common functions and data structures
  • C++ targets systems and applications programming, and efficient direct execution, while Java is a general-purpose language with enhanced portability that operates through a virtual machine
  • C++ completely replaces the C language with object-oriented and data-generic programming and Java’s syntax similar to C++; both languages can implement functionality implemented in the other language
  • C++ does not enable direct object-oriented programming and requires defined data structures and separate functions for manipulating those structures, while Java directly supports full object-oriented programming
  • Optimal runtime modules are created thereby, which minimizes memory and time consumption
  • Linkers and interpreters can readily interpret such variables, which minimizes program build time
  • Machine-code is more-easily generated under such circumstances, which minimizes compile time
  • No data-type has to be defined until compile-time, which makes top-level data-types flexible and reusable
  • Abstract during conceptualization and design, to specific in implementation and programming
  • Geographic agnosticity is maintained until runtime, when specific modules are remotely called
  • Memory utilization is not an issue since virtual memory is always available or swapping is used
  • Runtime timing requirements can be left to the compiler/linker to satisfy via its optimization capabilities
  • Graph
  • List
  • Queue
  • Set
  • #include <iostream>

#include <time.h>

using namespace std;

int main()

{

  time_t result = time(NULL);

  cout << “Local Time: ” << result << endl;

  cout << “Coordinated Universal Time: ” << result + (7*60*60) << endl;

  return 0;

}

  • #include <iostream>

#include <ctime>

using namespace std;

int main()

{

  time_t result = time(nullptr);

  cout << “Local Time: ” << asctime(localtime(&result)) << endl;

  cout << “Coordinated Universal Time: ” << asctime(gmtime(&result)) << endl;

  return 0;

}

  • #include <iostream>

#include <ctime>

using namespace std;

int main()

{

  time_t result = time(nullptr);

  cout << “Local Time: ” << asctime(localtime(&result)) << endl;

  cout << “Coordinated Universal Time: ” << asctime(system_clock(&result))<<endl;

  return 0;

}

  • #include <iostream>

#include <time.h>

using namespace std;

int main()

{

  time_t result = time(NULL);

  cout << “Local Time: ” << result << endl;

  cout << “Coordinated Universal Time: ” << result + (60*60) << endl;

  return 0;

}

  • #include <iostream>

#include <thread>

#include <mutex>

using namespace std;

mutex consoleMutex;

void workingThread (int id)

{

  int myID = id;

  consoleMutex.lock();

  std::cout << “Thread # ” << myID << ‘\n’;

  consoleMutex.unlock();

}

int main ()

{

  std::thread threads[10];

  for (int i = 0; i < 10; ++i)

    threads[i] = thread(workingThread, i + 1);

  for (auto& th : threads) th.join();

  return 0;

}

  • #include <iostream>

#include <thread>

#include <mutex>

using namespace std;

mutex consoleMutex;

void workingThread (int id)

{

  int myID = id;

  std::cout << “Thread # ” << myID << ‘\n’ << flush;

}

int main ()

{

  std::thread threads[10];

  for (int i = 0; i < 10; ++i)

    threads[i] = thread(workingThread, i + 1);

  for (auto& th : threads) th.join();

  return 0;

}

  • #include <iostream>

#include <thread>

#include <mutex>

using namespace std;

mutex consoleMutex;

void workingThread (int id)

{

  int myID = id;

  consoleMutex.lock();

  std::cout << “Thread # ” << myID << ‘\n’ << flush;

  consoleMutex.unlock();

}

int main ()

{

  std::thread threads[10];

  for (int i = 0; i < 10; ++i)

    threads[i] = thread(workingThread, i + 1);

  for (auto& th : threads) th.join();

  return 0;

}

  • #include <iostream>

#include <thread>

#include <mutex>

using namespace std;

mutex consoleMutex;

void workingThread (int id)

{

  int myID = id;

  this_thread::sleep_for(std::chrono::seconds(2));

  std::cout << “Thread # ” << myID << ‘\n’ << flush;

}

int main ()

{

  std::thread threads[10];

  for (int i = 0; i < 10; ++i)

    threads[i] = thread(workingThread, i + 1);

  for (auto& th : threads) th.join();

  return 0;

}

  • Arrays hold primitive types such as int, long, or double, while collections hold wrapper classes such as Integer, Long, or Double
  • Collections hold primitive types such as int, long, or double, while arrays hold wrapper classes such as Integer, Long, or Double
  • Arrays need to be assigned a static capacity when created, while collections vary in size automatically when objects are added or removed
  • Collections need to be assigned a static capacity when created, while arrays vary in size automatically when objects are added or removed
  • They are a more flexible version of an array, since elements have a specific order, duplicate elements are allowed, and elements can be placed in a specific position or searched for within the list
  • They are a more flexible version of a set, since elements do not have a specific order and duplicate elements are not allowed, but elements can be placed in a specific position and be searched for within the list
  • They are a more flexible version of a map, since elements are a key/data pair, duplicate elements are allowed, and elements cannot be placed in a specific position but can be searched for within the list using the key
  • They are a more flexible version of a queue, since elements are pushed onto the queue, duplicate elements are allowed, and elements cannot be placed in a specific position but are referenced only at the front or back of the queue
  • O(C×n−−√)�(�×�)
  • O(E×ln(n))�(�×ln⁡(�))
  • O(C×log2(n))�(�×log2⁡(�))
  • O((C−X)log10(n))�((�−�)log10(�))
  • Choosing the pivot point
  • Ensuring there is pre-sorted data
  • Implementing in the right language
  • Choosing between recursive or explicit implementation
  • When you have a large dataset
  • When you have a pre-sorted dataset
  • When you have a very small dataset
  • When you have a dataset managed by a SQL DBMS
  • Language and symbology
  • Algorithm and implementation
  • Source and assembler or byte code
  • Lines of source code and lines of executable code
  • To increase the quality of final software products
  • To help people naturally focus on the problem to be solved
  • To provide excellent support for CMMI software project requirements
  • To enable languages to be human-focused instead of machine-focused
  • C++ has no standardized byte-size limits for any primitive numeric types, while Java has standardized limits and sizes of all primitive numeric types on all platforms
  • In C++, primitive operations on numerical data always yield the same result from platform-to-platform, while in Java results from primitive operations on numerical data can vary from platform to platform
  • In C++, programs involving numeric data are not portable from platform to platform, while in Java all programs are fully portable from platform to platform as long as a JVM exists for the target platform
  • C++ has standardized minimum byte-size limits for all primitive numeric types and maximum byte sizes are platform-defined, while Java has standardized limits and sizes of all primitive numeric types on all platforms
  • They lead directly to efficient networked systems
  • They are specifically designed for shared and non-shared memory environments
  • They lead to a common language syntax that works well with most compilers and interpreters
  • They enable a disassociation of the computer and its languages from the problem to be solve
  • Data structures that are linear and associative
  • Local and remote hosting of program modules
  • Shared and non-shared memory for storing data structures
  • Compiled/linked and interpreted code for runtime implementation
  • Hardware interrupts that stopped programs
  • Flags that were set for programmers to check
  • Error messages that were sent to the console
  • Operating system interrupts that stopped programs
  • It is a way to check flags set by program components
  • It tends to reduce the complexity of error-handling code
  • It automatically expands lines of code to improve programmer productivity
  • It meets all international standards in code project administrative requirements
  • // File: Utilities.java

package com.company;

public class Utilities

{

  private boolean continueTask = true;

  public boolean get_continueTask() { return continueTask;}

  public void CallNext()

  {

    Integer[] theseIntegers = new Integer[99999];

    try

    {

      if(continueTask) CallNext(); else return;

    }

    catch (Exception e)

    {

      System.out.println(“*** Caught StackOverflowError. Point A.”);

      System.out.println(”    Unable to continue with this task.”);

      e.printStackTrace();

      continueTask = false;

      return;

    }

  }

}

// File: Main.java

package com.company;

public class Main

{

  public static void main(String[] args)

  {

    Utilities U = new Utilities();

    U.CallNext();

    if( ! U.get_continueTask())

      System.out.println

      (“\n… message to client … Unable to fulfill request.”);

  }

}

  • // File: Utilities.java

package com.company;

public class Utilities

{

  private boolean continueTask = true;

  public boolean get_continueTask() { return continueTask;}

  public void CallNext()

  {

    Integer[] theseIntegers = new Integer[99999];

    continueTask = false;

    CallNext();

    continueTask = true;

  }

}

// File: Main.java

package com.company;

public class Main

{

  public static void main(String[] args)

  {

    Utilities U = new Utilities();

    U.CallNext();

    if( ! U.get_continueTask())

      System.out.println

      (“\n… message to client … Unable to fulfill request.”);

  }

}

  • // File: Utilities.java

package com.company;

public class Utilities

{

  public void CallNext()

  {

    Integer[] theseIntegers = new Integer[99999];

    try

    {

      CallNext()

    }

    catch (StackOverflowError e) { }

  }

}

// File: Main.java

package com.company;

public class Main

{

  public static void main(String[] args)

  {

    Utilities U = new Utilities();

    U.CallNext();

  }

}

  • // File: Utilities.java

package com.company;

public class Utilities

{

public void CallNext()

{

Integer[] theseIntegers = new Integer[99999];

try

{

if(continueTask) CallNext(); else return;

}

catch (StackOverflowError e)

{

System.out.println(“*** Caught StackOverflowError. Point A.”);

System.out.println(”    Unable to continue with this task.”);

e.printStackTrace();

continueTask = false;

return;

}

}

}

// File: Main.java

package com.company;

public class Main

{

public static void main(String[] args)

{

Utilities U = new Utilities();

U.CallNext();

if( ! U.get_continueTask())

System.out.println

(“\n… message to client … Unable to fulfill request.\n”);

}

}

  • Recursive processes are far easier to understand and maintain. The server’s memory should be increased so that additional recursive steps can be taken by all processes.
  • The recursive process should be replaced by the explicit process. Documentation of the algorithm and its implementation should be brought up to date so that the code can be understood and maintained.
  • Java has compiler options to increase stackspace. This option should be employed. If memory continues to be a problem, additional memory should be added to the server since memory is cheap.
  • The server’s process documentation should be updated to show the limits of data-block size. A list of other servers that perform the required processing for larger data blocks should be made available in a help file.
  • You usually search for an exact match, but it might be better to allow for some cases where a close-enough match would bring satisfactory results
  • You usually assume that the target value is present, but it might be better to modify the basic algorithm so that “target not present” can be recognized
  • You usually want to start the search at one end or the other of the dataset, but it might be better to spawn two threads, each of which starts their search from different ends to search through the middle index
  • You usually have SQL databases that are readily segmented and are accessible via networked computers; rather than have one distributed process search the database, it might be better to have several computers engaged in the search
  • It returns any index whose element is equal to the target value, even if there are duplicate elements in the dataset; a solution is to reinitialize the search using a different “middle” index
  • It may return no indexes even if the target value is present; a solution is to search for pseudo-target values that are near to the target value, which ensures the target value will be found if present
  • It returns any index whose element is equal to the target value, even if there are duplicate elements in the dataset; a solution is to linearly search left and right of the index for all elements equal to the target value
  • It returns only the left-most index whose element is equal to the target value; a solution to ensure there are no elements in the dataset is to linearly search to the right of the index for all elements equal to the target value
  • To write and test classes and instances that represent the objects within the program design
  • To write correct, well-commented, and well-tested code that meets all specified project requirements
  • To establish an association between the machine model and a model of the problem that is being solved
  • To begin with a flowchart to show the flow of logic and then construct modules to enable that flowchart
  • Earlier languages were oriented toward the bits and bytes of computers, which meant that they did not enable writing portable code
  • Earlier languages enabled good solutions to particular types of problems, but they became awkward to use to solve problems outside of that domain
  • Earlier languages, like functional and modular languages, were insufficiently general in nature and do not support modern problem-solving techniques
  • Earlier programs were written with limited memory as the most critical resource, which did not let them generalize the way they implemented algorithms
  • Objects are independent, but subroutines are dependent and part of the codebase
  • Subroutines can be made re-entrant, but care is needed in managing accessed memory
  • There can be only one copy of a subroutine, but multiple objects can be created from a single class
  • Threads can always call subroutines multiple times at once, but there can be only one class instance
  • Primary use-cases, involvement of sponsors in projects, and classes instantiated by objects
  • Remote procedure calls, memory that can be shared or independent, and remote memory access
  • Language independence, functionality independent of data type, and programmer-defined data types
  • Mixed-language systems, geographical independence of functionality, and inter-module communication
  • Java does not allow direct memory access; C++ allows direct memory access.
  • Everything, every variable type, is an object in Java; such is not the case in C++.
  • Java has automatic consolidation of released memory; C++ does not automatically consolidate memory.
  • One can never cause memory to be orphaned in Java; it is possible to create orphaned memory in C++.
  • C++, since its Standard Template Library is far superior to Java’s Collection Library
  • C++, since it executes directly while Java requires the use of intermediate execution software
  • Java, since C++ takes much longer to write and test because it enables direct memory manipulation
  • Java, since its internal testing and documentation capability enables assurance of timing requirements
  • Store references to objects with a lookup key for accessing the object’s values
  • Insert items in a certain sequence and retrieve those items in the same sequence
  • Create a fixed-size vector that objects can be placed into for later indexed referencing
  • Create unordered collections that can be iterated and that contain each element at most once
  • A flag is set when it is not possible to continue processing because the information necessary to deal with the problem in the current context is not available
  • Hardware interrupts are automatically thrown when it is not possible for the CPU to continue processing because the information necessary to deal with the problem is not available
  • Software interrupts are automatically thrown when it is not possible to continue processing because the information necessary to deal with the problem in the current context is not available
  • if/else statements are used to detect situations where it is not possible to continue processing because the information necessary to deal with the problem in the current context is not available
CS 102 Introduction to Computer Science II Answer Key Saylor Academy 3
  • Mutex is essential because of the use of shared memory by the recursive functions; otherwise, the results will be incorrect
  • The program will run faster because of the use of simultaneous threads, and the computer will remain as reliable as it was before
  • The computer will not be able to handle simultaneous threads cast in this manner, but it would work if each thread were a process on a separate computer
  • The program will run faster for smaller problems, but it will be unable to cope with larger problems because the stack will fill up faster as it is used by simultaneous threads
  • List
  • Tree
  • Graph
  • Network
CS 102 Introduction to Computer Science II Answer Key Saylor Academy 4

A.

Option A

B.

Option B

C.

Option C

D.

Option D
  • Modules are always re-entrant, while objects are not
  • Multiple objects of the same class can be created and exist independently, while modules cannot be
  • Objects can be created and destroyed by threads, while modules can only be called from the main thread
  • Modules execute when encountered in the logic-flow of a program, while objects can be called from anywhere
  • Machine-focused evolved to solution-focused and finally to object-orientation
  • Languages evolved from those that few could work with to languages that many could work with
  • Object-orientation is an evolution of modular, which is itself an evolution of functional approaches
  • Machine-oriented languages evolved to human-oriented languages and then to object-oriented languages
  • It became impossible to call a class’ object method using an incorrect data type
  • They started to fully support functional, modular, and object-oriented approaches
  • It became unnecessary to write subroutines in the assembler to achieve timely execution
  • Their compilers and linkers have decreased the amount of memory and processing time consumed
  • package com. company;

import java.util.*;

public class ListExample

{

public static void main (String args [])

{

List<String> list = new ArrayList<String> ();

Iterator it = list. iterator ();

list.add(“Dog”);

list.add(“Cat”);

list.add(“Horse”);

list.add(“Cow”);

while (it. hasNext ())

{

String obj = (String)it. next ();

System.out.println(obj);

}

}

}

  • package com. company;

import java.util.*;

public class ListExample

{

public static void main (String args [])

{

List<String> list = new ArrayList<String> ();

Iterator it = list. iterator ();

list.add(“Dog”);

list.add(“Cat”);

list.add(“Horse”);

list.add(“Cow”);

for (String animal: list) System.out.println(animal);

}

}

  • package com. company;

import java.util.*;

public class ListExample

{

public static void main (String args [])

{

List<String> list = new ArrayList<String> ();

Iterator it = list. iterator ();

list.add(“Dog”);

list.add(“Cat”);

list.add(“Horse”);

list.add(“Cow”);

int length = list. size ();

for (int i = 0; i < length; i++)

{

String obj = (String)list.get(i);

System.out.println(obj);

}

}

}

  • package com. company;

import java.util.*;

public class ListExample

{

public static void main (String args [])

{

List<String> list = new ArrayList<String> ();

Iterator it = list. iterator ();

list.add(“Dog”);

list.add(“Cat”);

list.add(“Horse”);

list.add(“Cow”);

int length = list. size ();

for (int i = length – 1; i >= 0; i–)

{

String obj = (String)list.get(i);

System.out.println(obj);

}

}

}

  • #include <iostream>

#include <set>

using namespace std;

typedef struct {string key; string elements [10];} Record, * pRecord;

pRecord thisRecord;

set<pRecord> Database;

pair<set<pRecord>: iterator, bool> checkForDuplicateRecord;

int main ()

{

thisRecord = new Record;

thisRecord->key = “One Key to Career Development:”;

thisRecord->elements [0] = “Study”;

thisRecord->elements [1] = “Learn”;

thisRecord->elements [2] = “Work”;

thisRecord->elements [3] = “Produce”;

thisRecord->elements [4] = “Cycle Repeatedly”;

Database.insert(thisRecord);

for (auto key_value: Database)

{

cout << key_value->key << endl;

for (int i = 0; i < 5; i++) cout << key_value->elements[i] << endl;

}

checkForDuplicateRecord = Database.insert(thisRecord);

return 0;

}

  • #include <iostream>

#include <set>

using namespace std;

typedef struct {string key; string elements [10];} Record, * pRecord;

pRecord thisRecord;

set<pRecord> Database;

pair<set<pRecord>: iterator, bool> checkForDuplicateRecord;

int main ()

{

thisRecord = new Record;

thisRecord->key = “One Key to Career Development:”;

thisRecord->elements [0] = “Study”;

thisRecord->elements [1] = “Learn”;

thisRecord->elements [2] = “Work”;

thisRecord->elements [3] = “Produce”;

thisRecord->elements [4] = “Cycle Repeatedly”;

Database.insert(thisRecord);

for (auto key_value: Database)

{

cout << key_value->key << endl;

for (int i = 0; i < 5; i++) cout << key_value->elements[i] << endl;

}

checkForDuplicateRecord = Database.insert(thisRecord);

if (checkForDuplicateRecord.second)

cout << endl << “Duplicate record not inserted” << endl;

return 0;

}

  • #include <iostream>

#include <set>

using namespace std;

typedef struct {string key; string elements [10];} Record, * pRecord;

pRecord thisRecord;

set<pRecord> Database;

pair<set<pRecord>: iterator, bool> checkForDuplicateRecord;

int main ()

{

thisRecord = new Record;

thisRecord->key = “One Key to Career Development:”;

thisRecord->elements [0] = “Study”;

thisRecord->elements [1] = “Learn”;

thisRecord->elements [2] = “Work”;

thisRecord->elements [3] = “Produce”;

thisRecord->elements [4] = “Cycle Repeatedly”;

Database.insert(thisRecord);

for (auto key_value: Database)

{

cout << key_value->key << endl;

for (int i = 0; i < 5; i++) cout << key_value->elements[i] << endl;

}

checkForDuplicateRecord = Database.insert(thisRecord);

if (checkForDuplicateRecord.second == false)

cout << endl << “Duplicate record not inserted” << endl;

return 0;

}

  • #include <iostream>

#include <list>

using namespace std;

typedef struct {string key; string elements [10];} Record, * pRecord;

pRecord thisRecord;

list<pRecord> Database;

bool checkForDuplicateRecord;

int main ()

{

thisRecord = new Record;

thisRecord->key = “One Key to Career Development:”;

thisRecord->elements [0] = “Study”;

thisRecord->elements [1] = “Learn”;

thisRecord->elements [2] = “Work”;

thisRecord->elements [3] = “Produce”;

thisRecord->elements [4] = “Cycle Repeatedly”;

Database.push_back(thisRecord);

for (auto key_value: Database)

{

cout << key_value->key << endl;

for (int i = 0; i < 5; i++) cout << key_value->elements[i] << endl;

}

checkForDuplicateRecord = Database.push_back(thisRecord);

if (checkForDuplicateRecord == false)

cout << endl << “Duplicate record not inserted” << endl;

return 0;

}

  • #include <iostream>

using namespace std;

int main ()

{

int i;

do

{

cout << “Please enter an integer value (0 means quit): “;

cin << i;

if (i! = 0)

{

cout << “The value you entered is ” << i;

cout << ” and its double is ” << i * 2 << “.\n”;

}

} while (i! = 0);

return 0;

}

  • #include <iostream>

using namespace std;

int main ()

{

int i;

do

{

cout << “Please enter an integer value (0 means quit): “;

scanf (“%d”, &i);

if (i! = 0)

{

cout << “The value you entered is ” << i;

cout << ” and its double is ” << i * 2 << “.\n”;

}

} while (i! = 0);

return 0;

}

  • #include <iostream>

using namespace std;

int main ()

{

int i;

do

{

cout << “Please enter an integer value (0 means quit): “;

cin >> i;

if (i! = 0)

{

printf (“The value you entered is %d”, i;

printf (” and its double is %d.\n “, i * 2)”;

}

} while (i! = 0);

return 0;

}

  • #include <iostream>

using namespace std;

int main ()

{

int i;

do

{

cout << “Please enter an integer value (0 means quit): “;

cin >> i;

if (i! = 0)

{

cout << “The value you entered is ” << i;

cout << ” and its double is ” << i * 2 << “.\n”;

}

} while (i! = 0);

return 0;

}

  • package com. company;

import java.util.*;

class AnObject

{

public String objectName = “NotSpecified”;

public AnObject (String specification) {objectName = specification;}

public void GiveSpecification ()

{System.out.println(“Object’s Name is ” + objectName);}

}

public class Main

{

private static void AddObject (List<AnObject> objectList, AnObject thisObject)

{

if (objectList.contains(thisObject)! = true)

{

objectList.add(thisObject);

System.out.println(thisObject.objectName + ” added”);

}

else System.out.println(thisObject.objectName + ” not added”);

}

public static void main (String [] args)

{

List<AnObject> Objects = new LinkedList<AnObject> ();

AnObject thisObject = new AnObject (“First Object”);

Objects.add(thisObject);

Objects.add(thisObject);

System.out.println(Objects.size());

System.out.println(Objects.get (0). objectName);

}

}

  • package com. company;

import java.util.*;

class AnObject

{

public String objectName = “NotSpecified”;

public AnObject (String specification) {objectName = specification;}

public void GiveSpecification ()

{System.out.println(“Object’s Name is ” + objectName);}

}

public class Main

{

private static void AddObject (List<AnObject> objectList, AnObject thisObject)

{

objectList.add(thisObject);

}

public static void main (String [] args)

{

List<AnObject> Objects = new LinkedList<AnObject> ();

AnObject thisObject = new AnObject (“First Object”);

AddObject (Objects, thisObject);

AddObject (Objects, thisObject);

System.out.println(Objects.size());

System.out.println(Objects.get (0). objectName);

}

}

  • package com. company;

import java.util.*;

class AnObject

{

public String objectName = “NotSpecified”;

public AnObject (String specification) {objectName = specification;}

public void GiveSpecification ()

{System.out.println(“Object’s Name is ” + objectName);}

}

public class Main

{

private static void AddObject (List<AnObject> objectList, AnObject thisObject)

{

if (objectList.contains(thisObject) == true)

{

objectList.add(thisObject);

System.out.println(thisObject.objectName + ” added”);

}

else System.out.println(thisObject.objectName + ” not added”);

}

public static void main (String [] args)

{

List<AnObject> Objects = new LinkedList<AnObject> ();

AnObject thisObject = new AnObject (“First Object”);

AddObject (Objects, thisObject);

AddObject (Objects, thisObject);

System.out.println(Objects.size());

System.out.println(Objects.get (0). objectName);

}

}

  • package com. company;

import java.util.*;

class AnObject

{

public String objectName = “NotSpecified”;

public AnObject (String specification) {objectName = specification;}

public void GiveSpecification ()

{System.out.println(“Object’s Name is ” + objectName);}

}

public class Main

{

private static void AddObject (List<AnObject> objectList, AnObject thisObject)

{

if (objectList.contains(thisObject)! = true)

{

objectList.add(thisObject);

System.out.println(thisObject.objectName + ” added”);

}

else System.out.println(thisObject.objectName + ” not added”);

}

public static void main (String [] args)

{

List<AnObject> Objects = new LinkedList<AnObject> ();

AnObject thisObject = new AnObject (“First Object”);

AddObject (Objects, thisObject);

AddObject (Objects, thisObject);

System.out.println(Objects.size());

System.out.println(Objects.get (0). objectName);

}

}

  • package com. company;

class SampleThread extends Thread

{

private volatile String threadName;

SampleThread (String name)

{

threadName = name;

System.out.println(“Creating ” + threadName);

}

public void run ()

{

System.out.println(“Running ” + threadName);

for (int i = 4; i > 0; i–)

{

System.out.println(“Thread: ” + threadName + “, ” + i);

try {Thread.sleep(5);}

catch (InterruptedException e) {e. printStackTrace ();}

}

System.out.println(“Thread ” + threadName + ” exiting.”);

threadName = threadName + ” | Finished”;

}

public String getReturnValue () {return threadName;}

}

public class Main

{

public static void main (String args []) throws InterruptedException

{

SampleThread R1 = new SampleThread(“Thread-1″);

R1. start ();

while (R1. isAlive ()) {System.out.println(“Thread is alive”);};

System.out.println(“Have departed thread: ” + R1. getReturnValue ());

}

}

  • package com. company;

class SampleThread extends Thread

{

private volatile String threadName;

SampleThread (String name)

{

threadName = name;

System.out.println(“Creating ” + threadName);

}

public void run ()

{

System.out.println(“Running ” + threadName);

for (int i = 4; i > 0; i–)

{

System.out.println(“Thread: ” + threadName + “, ” + i);

try {Thread.sleep(5);}

catch (InterruptedException e) {e. printStackTrace ();}

}

System.out.println(“Thread ” + threadName + ” exiting.”);

threadName = threadName + ” | Finished”;

}

public void start () {System.out.println(“Starting ” + threadName);}

public String getReturnValue () {return threadName;}

}

public class Main

{

public static void main (String args []) throws InterruptedException

{

SampleThread R1 = new SampleThread(“Thread-1″);

R1. start ();

while (R1. isAlive ()) {System.out.println(“Thread is alive”);};

System.out.println(“Have departed thread: ” + R1. getReturnValue ());

}

}

  • package com. company;

class SampleThread extends Thread

{

private volatile String threadName;

SampleThread (String name)

{

threadName = name;

System.out.println(“Creating ” + threadName);

}

public void run ()

{

System.out.println(“Running ” + threadName);

for (int i = 4; i > 0; i–)

{

System.out.println(“Thread: ” + threadName + “, ” + i);

try {Thread.sleep(5);}

catch (InterruptedException e) {e. printStackTrace ();}

}

System.out.println(“Thread ” + threadName + ” exiting.”);

threadName = threadName + ” | Finished”;

}

public String getReturnValue () {return threadName;}

}

public class Main

{

public static void main (String args []) throws InterruptedException

{

SampleThread R1 = new SampleThread(“Thread-1″);

R1.run ();

while (R1. isAlive ()) {System.out.println(“Thread is alive”);};

System.out.println(“Have departed thread: ” + R1. getReturnValue ());

}

}

  • package com. company;

class SampleThread extends Thread

{

private volatile String threadName;

SampleThread (String name)

{

threadName = name;

System.out.println(“Creating ” + threadName);

}

public void run ()

{

System.out.println(“Running ” + threadName);

for (int i = 4; i > 0; i–)

{

System.out.println(“Thread: ” + threadName + “, ” + i);

try {Thread.sleep(5);}

catch (InterruptedException e) {e. printStackTrace ();}

}

System.out.println(“Thread ” + threadName + ” exiting.”);

threadName = threadName + ” | Finished”;

}

//public void start () {System.out.println(“Starting ” + threadName);}

public String getReturnValue () {return threadName;}

}

public class Main

{

public static void main (String args []) throws InterruptedException

{

SampleThread R1 = new SampleThread(“Thread-1″);

R1. start ();

R1. join ();

System.out.println(“Have departed thread: ” + R1. getReturnValue ());

}

}

  • public class Server

{

public static void main (String [] args) throws IOException

{

boolean Continue = true;

Integer port = 5000;

ServerSocket serverSocket = new ServerSocket(port);

serverSocket.setSoTimeout(10000);

while (Continue)

{

try

{

System.out.println(“Waiting for client on port ” +

serverSocket.getLocalPort());

Socket server = serverSocket.accept();

System.out.println(“Connected to client at address ” +

server. getRemoteSocketAddress ());

DataInputStream in = new DataInputStream (server. getInputStream ());

System.out.println(in. readUTF ());

DataOutputStream out = new DataOutputStream (server. getOutputStream ());

out. writeUTF (“Thank you for connecting to ” +

server. getLocalSocketAddress () + “\nGoodbye!”);

server. close ();

Continue = false;

}

catch (SocketTimeoutException s) {System.out.println(“Socket timeout”);}

catch (IOException e) {e. printStackTrace ();}

}

}

}

  • import java.net. *;

import java.io. *;

public class Server

{

public static void main (String [] args) throws IOException

{

boolean Continue = true;

Integer port = 5000;

ServerSocket serverSocket = new ServerSocket(port);

serverSocket.setSoTimeout(10000);

while (Continue)

{

System.out.println(“Waiting for client on port ” +

serverSocket.getLocalPort());

Socket server = serverSocket.accept();

System.out.println(“Connected to client at address ” +

server. getRemoteSocketAddress ());

DataInputStream in = new DataInputStream (server. getInputStream ());

System.out.println(in. readUTF ());

DataOutputStream out = new DataOutputStream (server. getOutputStream ());

out. writeUTF (“Thank you for connecting to ” +

server. getLocalSocketAddress () + “\nGoodbye!”);

server. close ();

Continue = false;

}

}

}

  • import java.net. *;

import java.io. *;

public class Server

{

public static void main (String [] args) throws IOException

{

boolean Continue = true;

Integer port = 5000;

ServerSocket serverSocket = new ServerSocket(port);

serverSocket.setSoTimeout(10000);

while (Continue)

{

try

{

System.out.println(“Waiting for client on port ” +

serverSocket.getLocalPort());

Socket server = serverSocket.accept();

System.out.println(“Connected to client at address ” +

server. getRemoteSocketAddress ());

DataInputStream in = new DataInputStream (server. getInputStream ());

System.out.println(in. readUTF ());

DataOutputStream out = new DataOutputStream (server. getOutputStream ());

out. writeUTF (“Thank you for connecting to ” +

server. getLocalSocketAddress () + “\nGoodbye!”);

server. close ();

Continue = false;

}

catch (SocketTimeoutException s) {System.out.println(“Socket timeout”);}

catch (IOException e) {e. printStackTrace ();}

}

}

}

  • import java.net. *;

import java.io. *;

public class Server

{

public static void main (String [] args) throws IOException

{

boolean Continue = true;

Integer port = -1;

ServerSocket serverSocket = new ServerSocket(port);

serverSocket.setSoTimeout(10000);

while (Continue)

{

try

{

System.out.println(“Waiting for client on port ” +

serverSocket.getLocalPort());

Socket server = serverSocket.accept();

System.out.println(“Connected to client at address ” +

server. getRemoteSocketAddress ());

DataInputStream in = new DataInputStream (server. getInputStream ());

System.out.println(in. readUTF ());

DataOutputStream out = new DataOutputStream (server. getOutputStream ());

out. writeUTF (“Thank you for connecting to ” +

server. getLocalSocketAddress () + “\nGoodbye!”);

server. close ();

Continue = false;

}

catch (SocketTimeoutException s) {System.out.println(“Socket timeout”);}

catch (IOException e) {e. printStackTrace ();}

}

}

}

  • Java’s exception handling includes standard exceptions, while C++ does not
  • Java enforces handling exceptions thrown by its components, while C++ does not
  • Java’s exception handling allows for programmer expressiveness, while C++ does not
  • Java is has a comparatively limited way of handling exceptions, while C++ is more robust
  • Historically they were passive; now they are active, and must be handled in both C++ and Java
  • Historically they had weak conditionals; now, expanded conditionals exist in both C++ and Java
  • Historically they were passive; now they are active, and automatically handled at some level in both C++ and Java
  • Historically they caused code bloat; now, this is still true, and both C++ and Java require writing a tremendous volume of code
  • Divide by zero
  • Out of memory
  • Custom exceptions
  • Square-root of negative number
  • #include <iostream>

using namespace std;

int main ()

{

try

{

int i = 5;

if (i == 5) throw “Division by zero.”;

int j = i / (i – 5);

}

catch (char* E)

{

cout << “*** Main: Exception. Point A. Type: ” << E << endl;

cout << “Program Abended” << endl;

return -1;

}

cout << “Program Ended Normally”;

return 0;

}

  • #include <iostream>

using namespace std;

int main ()

{

try

{

int i = 5;

if (i == 5) throw “Division by zero.”;

int j = i / (i – 5);

}

catch (const char* E)

{

cout << “*** Main: Exception. Point A. Type: ” << E << endl;

cout << “Program Abended” << endl;

return -1;

}

cout << “Program Ended Normally”;

return 0;

}

  • #include <iostream>

using namespace std;

int main ()

{

int i = 5;

int j = i / (i – 5);

cout << “Program Ended Normally”;

return 0;

}

  • #include <iostream>

using namespace std;

int main ()

{

try

{

int i = 5;

int j = i / (i – 5);

}

catch (Exception &E)

{

cout << “*** Main: Exception. Point A. Type: ” << E. what () << endl;

cout << “Program Abended” << endl;

return -1;

}

cout << “Program Ended Normally”;

return 0;

}

  • #include <iostream>

using namespace std;

class Polymorphic {public: void Member () {cout << “my member” << endl;}};

class NullPolymorphic: public exception

{

private: string feedback;

public: Polymorphic *newPolymorphic;

public:

NullPolymorphic (string feedback, Polymorphic *thisPolymorphic)

{

// some processing on constructor input values

thisPolymorphic = new Polymorphic (); // result of that processing

this->newPolymorphic = thisPolymorphic;

this->feedback = feedback;

}

const char* what () const throw () {return feedback.c_str ();}

};

int main ()

{

Polymorphic* pb = NULL;

try

{

pb = NULL;

if (pb == NULL)

throw NullPolymorphic

(“Exception: pb = NULL at Point A. New Polymorphic created.”, pb);

else pb->Member ();

}

catch (const NullPolymorphic &e)

{

cout << “An exception occurred: ” << endl << e. what () << ‘\n’;

cout << “*** Location: Module Main: Catch Statement: 001” << endl;

pb = e. newPolymorphic;

cout << “New pb value = ” << pb << endl;

}

cout << “Processing continues” << endl;

cout << “Program Ended Normally” << endl;

return 0;

}

  • #include <iostream>

#include <exception>

using namespace std;

class Polymorphic {public: void Member () {cout << “my member” << endl;}};

class NullPolymorphic: public exception

{

private: string feedback;

public: Polymorphic *newPolymorphic;

public:

NullPolymorphic (string feedback, Polymorphic *thisPolymorphic)

{

// some processing on constructor input values

thisPolymorphic = new Polymorphic (); // result of that processing

this->newPolymorphic = thisPolymorphic;

this->feedback = feedback;

}

const char* what () const throw () {return feedback.c_str ();}

};

int main ()

{

Polymorphic* pb = NULL;

try

{

pb = NULL;

if (pb == NULL)

throw NullPolymorphic

(“Exception: pb = NULL at Point A. New Polymorphic created.”, pb);

else pb->Member ();

}

catch (NullPointerException &e)

{

cout << “An exception occurred: ” << endl << e. what () << ‘\n’;

cout << “*** Location: Module Main: Catch Statement: 001” << endl;

pb = e. newPolymorphic;

cout << “New pb value = ” << pb << endl;

}

cout << “Processing continues” << endl;

cout << “Program Ended Normally” << endl;

return 0;

}

  • #include <iostream>

#include <exception>

using namespace std;

class Polymorphic {public: void Member () {cout << “my member” << endl;}};

class NullPolymorphic: public exception

{

private: string feedback;

public: Polymorphic *newPolymorphic;

public:

NullPolymorphic (string feedback, Polymorphic *thisPolymorphic)

{

// some processing on constructor input values

thisPolymorphic = new Polymorphic (); // result of that processing

this->newPolymorphic = thisPolymorphic;

this->feedback = feedback;

}

const char* what () const throw () {return feedback.c_str ();}

};

int main ()

{

Polymorphic* pb = NULL;

try

{

pb = NULL;

if (pb == NULL)

throw NullPolymorphic

(“Exception: pb = NULL at Point A. New Polymorphic created.”, pb);

else pb->Member ();

}

catch (const NullPolymorphic &e)

{

cout << “An exception occurred: ” << endl << e. what () << ‘\n’;

cout << “*** Location: Module Main: Catch Statement: 001” << endl;

pb = e. newPolymorphic;

cout << “New pb value = ” << pb << endl;

}

cout << “Processing continues” << endl;

cout << “Program Ended Normally” << endl;

return 0;

}

  • #include <iostream>

#include <exception>

using namespace std;

class Polymorphic {public: void Member () {cout << “my member” << endl;}};

class NullPolymorphic: public exception

{

private: string feedback;

public: Polymorphic *newPolymorphic;

public:

NullPolymorphic (string feedback, Polymorphic *thisPolymorphic)

{

// some processing on constructor input values

thisPolymorphic = new Polymorphic (); // result of that processing

this->newPolymorphic = thisPolymorphic;

this->feedback = feedback;

}

const char* what () const throw () {return feedback.c_str ();}

};

int main ()

{

Polymorphic* pb = NULL;

try

{

pb = NULL;

if (pb == NULL)

throw NullPolymorphic

(“Exception: pb = NULL at Point A. New Polymorphic created.”, pb);

else pb->Member ();

}

catch (const NullPolymorphic &e)

{

cout << “An exception occurred: ” << endl << e. what () << ‘\n’;

cout << “*** Location: Module Main: Catch Statement: 001” << endl;

pb = e. newPolymorphic;

cout << “New pb value = ” << pb << endl;

}

cout << “Processing continues” << endl;

cout << “Program Ended Normally” << endl;

return 0;

}

  • package com. company;

import java.util.*;

public class Main

{

public static void main (String [] args)

{

Map<Integer, String> clientData = new HashMap<Integer, String> ();

long messageSize = 999999;

long requiredMemory = 2 * messageSize;

String data = “”;

String messageData;

for (long i = 0; i < messageSize; i++) data = data + ” “;

System.out.println(data. length ());

Integer messageID = 0;

while(true)

{

try

{

messageData = new String ();

messageData = data; // receiving client data

clientData.put (messageID++, messageData);

// retrieving and processing stored client data

// removing client data when response generated

}

catch (java. lang. OutOfMemoryException e)

{

System.out.println(e. getMessage ());

System.out.println(“MessageID: ” + messageID.toString());

// retrieving and processing stored client data

// removing client data when response generated

for (int i = 0; i < 5; i++)

{

messageData = clientData.get (–messageID);

// process message data

clientData.remove(messageID, messageData);

}

}

}

}

}

  • package com. company;

import java.util.*;

public class Main

{

public static void main (String [] args)

{

Map<Integer, String> clientData = new HashMap<Integer, String> ();

long messageSize = 999999;

long requiredMemory = 2 * messageSize;

String data = “”;

String messageData;

for (long i = 0; i < messageSize; i++) data = data + ” “;

System.out.println(data. length ());

Boolean Continue = true;

Integer messageID = 0;

while(true)

{

try

{

if (Runtime.getRuntime(). freeMemory () <= requiredMemory)

throw new OutOfMemoryException

(“Insufficient memory for new client data.”);

messageData = new String ();

messageData = data; // receiving client data

clientData.put (messageID++, messageData);

// retrieving and processing stored client data

// removing client data when response generated

}

catch (Exception e)

{

System.out.println(e. getMessage ());

System.out.println(“MessageID: ” + messageID.toString());

// retrieving and processing stored client data

// removing client data when response generated

for (int i = 0; i < 5; i++)

{

messageData = clientData.get (–messageID);

// process message data

clientData.remove(messageID, messageData);

}

}

}

}

}

  • package com. company;

import java.util.*;

class OutOfMemoryException extends Exception

{

public OutOfMemoryException (String message)

{

super (“Custom Exception: ” + message);

}

}

public class Main

{

public static void main (String [] args)

{

Map<Integer, String> clientData = new HashMap<Integer, String> ();

long messageSize = 999999;

long requiredMemory = 2 * messageSize;

String data = “”;

String messageData;

for (long i = 0; i < messageSize; i++) data = data + ” “;

System.out.println(data. length ());

Boolean Continue = true;

Integer messageID = 0;

while(true)

{

try

{

if (Runtime.getRuntime(). freeMemory () <= requiredMemory)

throw new OutOfMemoryException

(“Insufficient memory for new client data.”);

messageData = new String ();

messageData = data; // receiving client data

clientData.put (messageID++, messageData);

// retrieving and processing stored client data

// removing client data when response generated

}

catch (OutOfMemoryException e)

{

System.out.println(e. getMessage ());

System.out.println(“MessageID: ” + messageID.toString());

// retrieving and processing stored client data

// removing client data when response generated

for (int i = 0; i < 5; i++)

{

messageData = clientData.get (–messageID);

// process message data

clientData.remove(messageID, messageData);

}

}

}

}

}

  • package com. company;

import java.util.*;

public class Main

{

public static void main (String [] args)

{

Map<Integer, String> clientData = new HashMap<Integer, String> ();

long messageSize = 999999;

long requiredMemory = 2 * messageSize;

String data = “”;

String messageData;

for (long i = 0; i < messageSize; i++) data = data + ” “;

System.out.println(data. length ());

Boolean Continue = true;

Integer messageID = 0;

while(true)

{

try

{

if (Runtime.getRuntime(). freeMemory () <= requiredMemory)

throw new OutOfMemoryException

(“Insufficient memory for new client data.”);

messageData = new String ();

messageData = data; // receiving client data

clientData.put (messageID++, messageData);

// retrieving and processing stored client data

// removing client data when response generated

}

catch (Error e)

{

System.out.println(e. getMessage ());

System.out.println(“MessageID: ” + messageID.toString());

// retrieving and processing stored client data

// removing client data when response generated

for (int i = 0; i < 5; i++)

{

messageData = clientData.get (–messageID);

// process message data

clientData.remove(messageID, messageData);

}

}

}

}

}

  • package com. company;

public class Main

{

public static void main (String [] args)

{

try

{

Double result = java. lang. StrictMath.sqrt(-1);

System.out.println(result);

}

catch (ArithmeticException e)

{

System.out.println(e. getMessage ());

e. printStackTrace ();

System.out.println(“Program Abended”);

System.exit(-1);

}

System.out.println(“Program Ended Normally”);

}

}

  • package com. company;

public class Main

{

public static void main (String [] args)

{

Double result = java. lang. StrictMath.sqrt(-1);

System.out.println(result);

System.out.println(“Program Ended Normally”);

}

}

  • package com. company;

public class Main

{

public static void main (String [] args)

{

try

{

Double result = sqrt (-1);

System.out.println(result);

}

catch (ArithmeticException e)

{

System.out.println(e. getMessage ());

e. printStackTrace ();

System.out.println(“Program Abended”);

System.exit(-1);

}

System.out.println(“Program Ended Normally”);

}

}

  • package com. company;

public class Main

{

public static void main (String [] args)

{

try

{

Double result = java. lang. StrictMath.sqrt(-1);

System.out.println(result);

if (result. isNaN ()) throw

new ArithmeticException (“Cannot take square root of negative number”);

}

catch (ArithmeticException e)

{

System.out.println(e. getMessage ());

e. printStackTrace ();

System.out.println(“Program Abended”);

System.exit(-1);

}

System.out.println(“Program Ended Normally”);

}

}

  • Let h+1=n.(2(2n−1)) −1
  • Let h+1=n.(2(2n)) −1,20=1
  • Let h+1=n.(2(2n−1)) −1,20=1
  • Let h+1=n.(2(2n+1)) −1,20=1
  • package com. company;

import java. lang. Math;

public class Main

{

public static Double clock (Double infectedPerPerson, Double clockTime)

{

Double peopleInfected;

if (clockTime == 0)

{

peopleInfected = 1.0;

System.out.println(“Time = ” + clockTime.toString() +

” | Number of people infected = ” +

peopleInfected.toString());

}

else

{

peopleInfected = clock (infectedPerPerson, clockTime – 1.0) +

Math.pow (infectedPerPerson, clockTime);

System.out.println(“Time = ” + clockTime.toString() +

” | Number of people infected = ” +

peopleInfected.toString());

}

}

public static void main (String [] args)

{

Double infectedPerPerson = 3.0;

Double totalTime = 3.0;

Double totalInfected = clock (infectedPerPerson, totalTime);

}

}

#include <iostream>

using namespace std;

double clock (double infectedPerPerson, double clockTime)

{

double peopleInfected;

if (clockTime == 0)

{

peopleInfected = 1.0;

cout << “Time = ” << clockTime <<

” | Number of people infected = ” <<

peopleInfected << endl;

}

else

{

peopleInfected = clock (infectedPerPerson, clockTime – 1) +

pow (infectedPerPerson, clockTime);

cout << “Time = ” << clockTime <<

” | Number of people infected = ” <<

peopleInfected << endl;

}

}

int main ()

{

double infectedPerPerson = 3.0;

double totalTime = 3.0;

double totalInfected = clock (infectedPerPerson, totalTime);

return 0;

}

  • package com. company;

public class Main

{

public static Double clock (Double infectedPerPerson, Double clockTime)

{

Double peopleInfected;

if (clockTime == 0)

{

peopleInfected = 1.0;

System.out.println(“Time = ” + clockTime.toString() +

” | Number of people infected = ” +

peopleInfected.toString());

}

else

{

peopleInfected = clock (infectedPerPerson, clockTime – 1.0) +

Math.pow (infectedPerPerson, clockTime);

System.out.println(“Time = ” + clockTime.toString() +

” | Number of people infected = ” +

peopleInfected.toString());

}

return peopleInfected;

}

public static void main (String [] args)

{

Double infectedPerPerson = 3.0;

Double totalTime = 3.0;

Double totalInfected = clock (infectedPerPerson, totalTime);

}

}

#include <iostream>

double clock (double infectedPerPerson, double clockTime)

{

double peopleInfected;

if (clockTime == 0)

{

peopleInfected = 1.0;

cout << “Time = ” << clockTime <<

” | Number of people infected = ” <<

peopleInfected << endl;

}

else

{

peopleInfected = clock (infectedPerPerson, clockTime – 1) +

pow (infectedPerPerson, clockTime);

cout << “Time = ” << clockTime <<

” | Number of people infected = ” <<

peopleInfected << endl;

}

return peopleInfected;

}

int main ()

{

double infectedPerPerson = 3.0;

double totalTime = 3.0;

double totalInfected = clock (infectedPerPerson, totalTime);

return 0;

}

  • package com. company;

import java. lang. Math;

public class Main

{

public static Double clock (Double infectedPerPerson, Double clockTime)

{

Double peopleInfected;

if (clockTime == 0)

{

System.out.println(“Time = ” + clockTime.toString() +

” | Number of people infected = ” +

peopleInfected.toString());

peopleInfected = 1.0;

}

else

{

System.out.println(“Time = ” + clockTime.toString() +

” | Number of people infected = ” +

peopleInfected.toString());

peopleInfected = clock (infectedPerPerson, clockTime – 1.0) +

Math.pow (infectedPerPerson, clockTime);

}

return peopleInfected;

}

public static void main (String [] args)

{

Double infectedPerPerson = 3.0;

Double totalTime = 3.0;

Double totalInfected = clock (infectedPerPerson, totalTime);

}

}

#include <iostream>

using namespace std;

double clock (double infectedPerPerson, double clockTime)

{

double peopleInfected;

if (clockTime == 0)

{

cout << “Time = ” << clockTime <<

” | Number of people infected = ” <<

peopleInfected << endl;

peopleInfected = 1.0;

}

else

{

cout << “Time = ” << clockTime <<

” | Number of people infected = ” <<

peopleInfected << endl;

peopleInfected = clock (infectedPerPerson, clockTime – 1) +

pow (infectedPerPerson, clockTime);

}

return peopleInfected;

}

int main ()

{

double infectedPerPerson = 3.0;

double totalTime = 3.0;

double totalInfected = clock (infectedPerPerson, totalTime);

return 0;

}

  • package com. company;

import java. lang. Math;

public class Main

{

public static Double clock (Double infectedPerPerson, Double clockTime)

{

Double peopleInfected;

if (clockTime == 0)

{

peopleInfected = 1.0;

System.out.println(“Time = ” + clockTime.toString() +

” | Number of people infected = ” +

peopleInfected.toString());

}

else

{

peopleInfected = clock (infectedPerPerson, clockTime – 1.0) +

Math.pow (infectedPerPerson, clockTime);

System.out.println(“Time = ” + clockTime.toString() +

” | Number of people infected = ” +

peopleInfected.toString());

}

return peopleInfected;

}

public static void main (String [] args)

{

Double infectedPerPerson = 3.0;

Double totalTime = 3.0;

Double totalInfected = clock (infectedPerPerson, totalTime);

}

}

#include <iostream>

using namespace std;

double clock (double infectedPerPerson, double clockTime)

{

double peopleInfected;

if (clockTime == 0)

{

peopleInfected = 1.0;

cout << “Time = ” << clockTime <<

” | Number of people infected = ” <<

peopleInfected << endl;

}

else

{

peopleInfected = clock (infectedPerPerson, clockTime – 1) +

pow (infectedPerPerson, clockTime);

cout << “Time = ” << clockTime <<

” | Number of people infected = ” <<

peopleInfected << endl;

}

return peopleInfected;

}

int main ()

{

double infectedPerPerson = 3.0;

double totalTime = 3.0;

double totalInfected = clock (infectedPerPerson, totalTime);

return 0;

}

  • O(C×n−−√)
Option A
  • O(E×ln(n))
Option B
  • O(C×log2(n))
Option C
  • O((C−X) log10(n))
Option D
  • Rectangular array and triangular array
  • Depth-first and breadth-first in an n-ary tree
  • List and queue with highest and lowest at opposite ends
  • Circular nodes with the largest and smallest values adjacent and sequential values linked one by one
  • Interfaces to public libraries of data structures and functions
  • A collection of common functions that spawn threads as needed
  • Insertable code modules that lend themselves easily to copy-and-paste
  • Data structures and associated functionality that are a formal part of the language.
  • The explicit and recursive versions provide comparable throughput; they use essentially the same code and so should be retained within the system
  • Computers and their maintenance are so cheap in this modern era that a computer with appropriate memory and high-speed cpu should be purchased to replace the existing server hardware
  • The explicit version provides far-better throughput, especially as data sizes grow, and since it is expensive to maintain two blocks of code that do the same thing, the recursive version should be discarded
  • A study should be made of the memory utilization of the two routines before a decision is made on which one to use; typically, recursive implementations employ far less memory than explicit implementations

About Clear My Certification

Check Also

CS402 Computer Communications and Networks

CS402: Computer Communications and Networks Certification Exam Answers

Computer communications and networks refer to the systems and infrastructure that enable communication and data …

Leave a Reply

Your email address will not be published. Required fields are marked *