Questions
Run the following code. Discuss the output result, i.e. the value of seq variable. #include <stdio.h>...

Run the following code. Discuss the output result, i.e. the value of seq variable.

#include <stdio.h>

#include <unistd.h>

int main()

{ int seq = 0; if(fork()==0) { printf("Child! Seq=%d\n", ++seq); }

else { printf("Parent! Seq=%d\n", ++seq);

} printf("Both! Seq=%d\n", ++seq); return 0; }

In: Computer Science

If answer can be shown using a c++ program and leave comments it will be very...

If answer can be shown using a c++ program and leave comments it will be very appreciated!!!

A bank charges $10 per month plus the following check fees for a commercial checking account: $0.10 each for fewer than 20 checks $0.08 each for 20-39 checks $0.06 each for 40-59 checks $0.04 each for 60 or more checks The bank also charges an extra $15.00 if the balance of the account falls below $400 (before any check fees are applied). Write a program that asks for the beginning balance and the number of check written. Compute and display the bank's service fees for the month. Input Validation: Do not accept a negative value for the number of checks written. If a negative value is given for the beginning balance, display an urgent message indicating the account is overdrawn.

Beginning balance: $-100 Number of checks written: 30 Your account is overdrawn! The bank fee this month is $27.40

Beginning balance: $400.00 Number of checks written: -20 Number of checks must be zero or more.

Beginning balance: $300.00 Number of checks written: 36 The bank fee this month is $27.88

Beginning balance: $300.00 Number of checks written: 47 The bank fee this month is $27.82

Beginning balance: $350.00 Number of checks written: 5 The bank fee this month is $25.50

Beginning balance: $300.00 Number of checks written: 70 The bank fee this month is $27.80

In: Computer Science

Program 1: Stay on the Screen! Animation in video games is just like animation in movies...

Program 1: Stay on the Screen! Animation in video games is just like animation in movies – it’s drawn image by image (called “frames”). Before the game can draw a frame, it needs to update the position of the objects based on their velocities (among other things). To do that is relatively simple: add the velocity to the position of the object each frame. For this program, imagine we want to track an object and detect if it goes off the left or right side of the screen (that is, it’s X position is less than 0 and greater than the width of the screen, say, 100). Write a program that asks the user for the starting X and Y position of the object as well as the starting X and Y velocity, then prints out its position each frame until the object moves off of the screen. Design (pseudocode) for this program

Sample run 1:

Enter the starting X position: 50

Enter the starting Y position: 50

Enter the starting X velocity: 4.7

Enter the starting Y velocity: 2

X:50 Y:50

X:54.7 Y:52

X:59.4 Y:54

X:64.1 Y:56

X:68.8 Y:58

X:73.5 Y:60

X:78.2 Y:62

X:82.9 Y:64

X:87.6 Y:66

X:92.3 Y:68

X:97 Y:70

X:101.7 Y:72

In: Computer Science

Instructions Write the definitions of the member functions of the class integerManipulation not given in Example...

Instructions

Write the definitions of the member functions of the class integerManipulation not given in Example 10-11. Also, add the following operations to this class:

  1. Split the number into blocks of n-digit numbers starting from right to left and find the sum of these n-digit numbers. (Note that the last block may not have n digits. If needed add additional instance variables.)
  2. Determine the number of zeroes.
  3. Determine the number of even digits.
  4. Determine the number of odd digits

Also, write a program to test theclass integerManipulation.

The header file for class integerManipulation has been provided for you.

integerManipulation.h:

class integerManipulation
{
public:
void setNum(long long n);
//Function to set num.
//Postcondition: num = n;

long long getNum();
//Function to return num.
//Postcondition: The value of num is returned.

void reverseNum();
//Function to reverse the digits of num.
//Postcondition: revNum is set to num with digits in
// in the reverse order.

void classifyDigits();
//Function to count the even, odd, and zero digits of num.
//Postcondition: evenCount = the number of even digits in num.
// oddCount = the number of odd digits in num.

int getEvensCount();
//Function to return the number of even digits in num.
//Postcondition: The value of evensCount is returned.

int getOddsCount();
//Function to return the number of odd digits in num.
//Postcondition: The value of oddscount is returned.

int getZerosCount();
//Function to return the number of zeros in num.
//Postcondition: The value of zerosCount is returned.

int sumDigits();
//Function to return the sum of the digits of num.
//Postcondition: The sum of the digits is returned.

integerManipulation(long long n = 0);
//Constructor with a default parameter.
//The instance variable num is set accordingto the parameter,
//and other instance variables are set to zero.
//The default value of num is 0;
//Postcondition: num = n; revNum = 0; evenscount = 0;
// oddsCount = 0; zerosCount = 0;

private:
long long num;
long long revNum;
int evensCount;
int oddsCount;
int zerosCount;
};

integerManipulationlmp.cpp:

main.cpp:

#include <iostream>

using namespace std;

int main() {
// Write your main here
return 0;
}

In: Computer Science

I need to access the values in the pizzaLocations array when main.cpp is run. The values...

I need to access the values in the pizzaLocations array when main.cpp is run. The values include name, address, city, postalCode, province, latitude, longitude, priceRangeMax, priceRangeMin. I tried declaring getter functions, but that does not work.

How do I access the values? Do I need to declare a function to return the values?

  • operator[](size_t) - This should return the location with the matching index. For example if given an index of 3, you should return the location at index 3 in the list.

#pragma once
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>

using std::getline;
using std::ifstream;
using std::string;
using std::stringstream;


struct Location {
   string name, address, city, postalCode, province;
   double latitude, longitude;
   int priceRangeMin, priceRangeMax;

   string getName(){ return name};

   string getAddress(){ return address};

   string getCity(){ return city};

   string getPostalCode(){ return postalCode};

   string getProvince(){ return province};

   double getLatitude(){ return latitude};

   double getLongitude(){ return longitude};

   int getPriceRangeMin(){ return priceRangeMin};

   int getPriceRangeMax(){ return priceRangeMax};
};

class PizzaZine {
   private:
      Location* pizzaLocations;
      size_t size;

   public:
      //default constructor

      PizzaZine()

      {

         pizzaLocations = new Location[50];

         this->size = 50;

      }

      //dynamically allocate array with user specified size

      PizzaZine(size_t size) { 

                pizzaLocations = new Location[size];

                this->size = size;

        }

      //destruct constructor

      ~PizzaZine()

      {

         delete[] pizzaLocations;

      }

      Location &operator[](size_t);//return the desired size for array

      // This function is implemented for you
      void readInFile(const string &);
};


Location &PizzaZine::operator[](size_t index)

{

   return pizzaLocations[index];

}

//this function has been implemented for you

void PizzaZine::readInFile(const string &filename) {
   ifstream inFile(filename);
   Location newLoc; //newLoc locally stores values of pizzaLocations?

   string line;
   string cell;

  

   // Read each line
   for (int i = 0; i < size; ++i) {
       // Break each line up into 'cells'
      getline(inFile, line);
    stringstream lineStream(line);


      while (getline(lineStream, newLoc.name, ',')) {
         getline(lineStream, newLoc.address, ',');
         getline(lineStream, newLoc.city, ',');
         getline(lineStream, cell, ',');
         if (!cell.empty()) {
            newLoc.postalCode = stoul(cell);
         }

     

         getline(lineStream, newLoc.province, ',');
         getline(lineStream, cell, ',');
         newLoc.latitude = stod(cell);
         getline(lineStream, cell, ',');
         newLoc.longitude = stod(cell);

         newLoc.priceRangeMin = -1;
         getline(lineStream, cell, ',');
         if (!cell.empty()) {
            newLoc.priceRangeMin = stoul(cell);
         }

         newLoc.priceRangeMax = -1;
         getline(lineStream, cell, ',');
         if (!cell.empty() && cell != "\r") {
            newLoc.priceRangeMax = stoul(cell);
         }


         pizzaLocations[i] = newLoc; //how do I retrieve the values in pizzaLocations once main.cpp is called?
      }//end of while loop
   }//end of for loop
}//end of readInFile function

In: Computer Science

How can I write java program code that do reverse, replace, remove char from string without...

How can I write java program code that do reverse, replace, remove char from string without using reverse, replace, remove method.

Only string method that I can use are length, concat, charAt, substring, and equals (or equalsIgnoreCase).

In: Computer Science

Implement the addSecond method in IntSinglyLinkedList. This method takes an Integer as an argument and adds...

Implement the addSecond method in IntSinglyLinkedList. This method takes an Integer as an argument and adds it as the second element in the list.

Here is an example of adding the Integer 7 to a list with two elements.

Abstract view: addSecond(7) on the list [12, 100] turns the list into [12, 7, 100]

Implement the rotateLeft method in IntSinglyLinkedList. It moves all elements closer to the front of the list by one space, moving the front element to be the last.

For example, here is what it looks like to rotateLeft once.

Abstract view: rotateLeft() on the list [12, 7, 100] turns the list into [7, 100, 12]

IntSinglyLinkedListTest.java

package net.datastructures;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import static org.junit.Assert.*;

public class IntSinglyLinkedListTest {

    @Test
    public void addSecondTest1() {
        IntSinglyLinkedList s = new IntSinglyLinkedList();
        s.addFirst(12);
        s.addSecond(7);
        // System.out.println(s);
        assertEquals(2, s.size());
        assertEquals(7, (int)s.last());
        assertEquals(12, (int)s.first());
    }

    @Test
    public void addSecondTest2() {
        IntSinglyLinkedList s = new IntSinglyLinkedList();
        s.addFirst(12);
        s.addFirst(7);
        s.addSecond(6);
        assertEquals(3, s.size());
        assertEquals(12, (int)s.last());
        assertEquals(7, (int)s.first());
    }

    @Test
    public void addSecondTest3() {
        IntSinglyLinkedList s = new IntSinglyLinkedList();
        s.addFirst(12);
        s.addSecond(7);
        s.addSecond(6);
        s.addSecond(1);
        assertEquals(4, s.size());
        assertEquals(7, (int)s.last());
        assertEquals(12, (int)s.first());
        assertEquals(12, (int)s.removeFirst());
        assertEquals(1, (int)s.first());
        assertEquals(1, (int)s.removeFirst());
        assertEquals(6, (int)s.first());
    }

    @Test
    public void rotateLeft1() {
        IntSinglyLinkedList s = new IntSinglyLinkedList();
        s.addFirst(7);
        s.addFirst(6);
        s.addFirst(5);
        s.addFirst(4);
        s.addFirst(3);
        s.rotateLeft();
        assertEquals(4, (int)s.first());
        assertEquals(3, (int)s.last());
        s.rotateLeft();
        assertEquals(5, (int)s.first());
        assertEquals(4, (int)s.last());
        s.rotateLeft();
        assertEquals(6, (int)s.first());
        assertEquals(5, (int)s.last());
        s.rotateLeft();
        assertEquals(7, (int)s.first());
        assertEquals(6, (int)s.last());
        s.rotateLeft();
        assertEquals(3, (int)s.first());
        assertEquals(7, (int)s.last());
    }
}

IntSinglyLinkedList.java

/*
 * Copyright 2014, Michael T. Goodrich, Roberto Tamassia, Michael H. Goldwasser
 *
 * Developed for use with the book:
 *
 *    Data Structures and Algorithms in Java, Sixth Edition
 *    Michael T. Goodrich, Roberto Tamassia, and Michael H. Goldwasser
 *    John Wiley & Sons, 2014
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package net.datastructures;

/**
 * A basic singly linked list implementation.
 *
 * @author Michael T. Goodrich
 * @author Roberto Tamassia
 * @author Michael H. Goldwasser
 */

/* CS2230
This version of IntSinglyLinkedList replaces the generic type Integer
with Integer. It may be easier to read if generic types
are hurting your brain.
*/

public class IntSinglyLinkedList {
    //---------------- nested Node class ----------------
    /**
     * Node of a singly linked list, which stores a reference to its
     * element and to the subsequent node in the list (or null if this
     * is the last node).
     */
    private static class Node {

        /** The element stored at this node */
        private Integer element;            // reference to the element stored at this node

        /** A reference to the subsequent node in the list */
        private Node next;         // reference to the subsequent node in the list

        /**
         * Creates a node with the given element and next node.
         *
         * @param e  the element to be stored
         * @param n  reference to a node that should follow the new node
         */
        public Node(Integer e, Node n) {
            element = e;
            next = n;
        }

        // Accessor methods
        /**
         * Returns the element stored at the node.
         * @return the element stored at the node
         */
        public Integer getElement() { return element; }

        /**
         * Returns the node that follows this one (or null if no such node).
         * @return the following node
         */
        public Node getNext() { return next; }

        // Modifier methods
        /**
         * Sets the node's next reference to point to Node n.
         * @param n    the node that should follow this one
         */
        public void setNext(Node n) { next = n; }
    } //----------- end of nested Node class -----------

    // instance variables of the IntSinglyLinkedList
    /** The head node of the list */
    private Node head = null;               // head node of the list (or null if empty)

    /** The last node of the list */
    private Node tail = null;               // last node of the list (or null if empty)

    /** Number of nodes in the list */
    private int size = 0;                      // number of nodes in the list

    /** Constructs an initially empty list. */
    public IntSinglyLinkedList() { }              // constructs an initially empty list

    // access methods
    /**
     * Returns the number of elements in the linked list.
     * @return number of elements in the linked list
     */
    public int size() { return size; }

    /**
     * Tests whether the linked list is empty.
     * @return true if the linked list is empty, false otherwise
     */
    public boolean isEmpty() { return size == 0; }

    /**
     * Returns (but does not remove) the first element of the list
     * @return element at the front of the list (or null if empty)
     */
    public Integer first() {             // returns (but does not remove) the first element
        if (isEmpty()) return null;
        return head.getElement();
    }

    /**
     * Returns (but does not remove) the last element of the list.
     * @return element at the end of the list (or null if empty)
     */
    public Integer last() {              // returns (but does not remove) the last element
        if (isEmpty()) return null;
        return tail.getElement();
    }

    // update methods
    /**
     * Adds an element to the front of the list.
     * @param e  the new element to add
     */
    public void addFirst(Integer e) {                // adds element e to the front of the list
        head = new Node(e, head);              // create and link a new node
        if (size == 0)
            tail = head;                           // special case: new node becomes tail also
        size++;
    }

    /**
     * Adds an element to the end of the list.
     * @param e  the new element to add
     */
    public void addLast(Integer e) {                 // adds element e to the end of the list
        Node newest = new Node(e, null);    // node will eventually be the tail
        if (isEmpty())
            head = newest;                         // special case: previously empty list
        else
            tail.setNext(newest);                  // new node after existing tail
        tail = newest;                           // new node becomes the tail
        size++;
    }

    /**
     * Removes and returns the first element of the list.
     * @return the removed element (or null if empty)
     */
    public Integer removeFirst() {                   // removes and returns the first element
        if (isEmpty()) return null;              // nothing to remove
        Integer answer = head.getElement();
        head = head.getNext();                   // will become null if list had only one node
        size--;
        if (size == 0)
            tail = null;                           // special case as list is now empty
        return answer;
    }

    @SuppressWarnings({"unchecked"})
    public boolean equals(Object o) {
        if (o == null) return false;
        if (getClass() != o.getClass()) return false;
        IntSinglyLinkedList other = (IntSinglyLinkedList) o;   // use nonparameterized type
        if (size != other.size) return false;
        Node walkA = head;                               // traverse the primary list
        Node walkB = other.head;                         // traverse the secondary list
        while (walkA != null) {
            if (!walkA.getElement().equals(walkB.getElement())) return false; //mismatch
            walkA = walkA.getNext();
            walkB = walkB.getNext();
        }
        return true;   // if we reach this, everything matched successfully
    }

    public void rotateLeft() {

    }

    public void addSecond(Integer e) {

    }

    /**
     * Produces a string representation of the contents of the list.
     * This exists for debugging purposes only.
     */
    public String toString() {
        StringBuilder sb = new StringBuilder("(");
        Node walk = head;
        while (walk != null) {
            sb.append(walk.getElement());
            if (walk != tail)
                sb.append(", ");
            walk = walk.getNext();
        }
        sb.append(")");
        return sb.toString();
    }

    public static void main(String[] args) {
        IntSinglyLinkedList sl = new IntSinglyLinkedList();
        sl.addLast(100);
        sl.addLast(200);
        sl.addLast(300);
        System.out.println(sl.toString());
        System.out.println("Removed " + sl.removeFirst());
        System.out.println(sl.toString());
    }
}

In: Computer Science

To the TwoDArray class, add a method called sumCols() that sums the elements in each column...

To the TwoDArray class, add a method called sumCols() that sums the elements in each column and displays the sum for each column. Add appropriate code in main() of the TwoDArrayApp class to execute the sumCols() method.

/**

* TwoDArray.java

*/

public class TwoDArray

{

private int a[][];

private int nRows;

public TwoDArray(int maxRows, int maxCols) //constructor

{

a = new int[maxRows][maxCols];

nRows = 0;

}

//******************************************************************

public void insert (int[] row)

{

a[nRows] = row;

nRows++;

}

//******************************************************************

public void display()

{

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

{

for (int j = 0; j < a[0].length; j++)

System.out.format("%5d", a[i][j]);

System.out.println(" ");

}

}

}

/**

* TwoDArrayApp.java

*/

public class TwoDArrayApp

{

public static void main(String[] args)

{

int maxRows = 20;

int maxCols = 20;

TwoDArray arr = new TwoDArray(maxRows, maxCols);

int b[][] = {{1, 2, 3, 4}, {11, 22, 33, 44}, {2, 4, 6, 8},{100, 200, 300,

400}};

arr.insert(b[0]); arr.insert(b[1]); arr.insert(b[2]); arr.insert(b[3]);

System.out.println("The original matrix: ");

arr.display();

}

}

In: Computer Science

Write a short message of between 15 and 40 characters to your classmates. Encode it using...

Write a short message of between 15 and 40 characters to your classmates. Encode it using a linear affine cipher with n=26. Post the message to the “Encrypted Messages” thread but do not give the “a” and “b” that you utilized.

Also post your own initial response thread in which you propose at least one way that you might try to decipher messages without the key.

In: Computer Science

what do you think the coding for carplay is ? give some examples of the code...

what do you think the coding for carplay is ? give some examples of the code they would've used design etc.

In: Computer Science

In python Consider the tuple t = (2,3,4,5). Write a function tuList( t ) that takes...

In python Consider the tuple t = (2,3,4,5). Write a function tuList( t ) that takes in a tuple, makes a list out of it, and also creates a new list of all possible sums of elements of the list

In: Computer Science

Java language Exercise #2: Design a Lotto class with one array instance variable to hold three...

Java language

Exercise #2:
Design a Lotto class with one array instance variable to hold three random integer values (from 1 to 9). Include a constructor that randomly populates the array for a lotto object. Also, include a method in the class to return the array.
Use this class in the driver class (LottoTest.java) to simulate a simple lotto game in which the user chooses a number between 3 and 27. The user runs the lotto up to 5 times ( by creating an object of Lotto class each time and with that three random integer values will be stored in objects’s array instance variable) and each time the sum of lotto numbers (sum of three random integers values) is calculated. If the number chosen by the user matches the sum, the user wins and the game ends. If the number does not match the sum within five rolls, the computer wins.


Exercise #3:
Write a Java class that implements a static method – SortNumbers(int… numbers) with variable number of arguments. The method should be called with different numbers of parameters and does arrange the numbers in descending order. Call the method within main method of the driver classand display the results.

In: Computer Science

using C++ 23. Savings Account Balance Write a program that calculates the balance of a savings...

using C++

23. Savings Account Balance
Write a program that calculates the balance of a savings account at the end of a three-
month period. It should ask the user for the starting balance and the annual interest
rate. A loop should then iterate once for every month in the period, performing the
following steps:
A) Ask the user for the total amount deposited into the account during that month
and add it to the balance. Do not accept negative numbers.
B) Ask the user for the total amount withdrawn from the account during that
month and subtract it from the balance. Do not accept negative numbers or
numbers greater than the balance after the deposits for the month have been
added in.
C) Calculate the interest for that month. The monthly interest rate is the annual
interest rate divided by 12. Multiply the monthly interest rate by the average of
that month’s starting and ending balance to get the interest amount for the
month. This amount should be added to the balance.
After the last iteration, the program should display a report that includes the following
information:
• starting balance at the beginning of the three-month period
• total deposits made during the three months
• total withdrawals made during the three months
• total interest posted to the account during the three months
• final balance

test case:

Test Case1:

Welcome to Your Bank!
What is your starting Balance? $100
What is the annual interest rate?. Please enter whole value. For example 6 for 6% :6

Month #1
Current Balance: $100.00
Please enter total amount of deposits: $2000
Please enter total amount of withdrawals: $200
New Balance: $1905.00

Month #2
Current Balance: $1905.00
Please enter total amount of deposits: $3000
Please enter total amount of withdrawals: $2000
New Balance: $2917.03

Month #3
Current Balance: $2917.03
Please enter total amount of deposits: $4000
Please enter total amount of withdrawals: $2000
New Balance: $4936.61

Start Balance:         $100.00
Total Deposits:        $9000.00
Total Withdrawals:     $4200.00
Total Interest Earned: $36.61
Final Balance:         $4936.61

In: Computer Science

Convert the following 32-bit IEEE floating point numbers to decimal: 0100 1100 1110 0110 1111 1000...

Convert the following 32-bit IEEE floating point numbers to decimal:

0100 1100 1110 0110 1111 1000 0000 0000
1011 0101 1110 0110 1010 0110 0000 0000

Determine whether or not the following pairs are equivalent by constructing truth tables:

[(wx'+y')(w'y+z)] and [(wx'z+y'z)]
[(wz'+xy)] and [(wxz'+xy+x'z')]

Using DeMorgan’s Law and Boolean algebra, convert the following expressions into simplest form:

(a'd)'
(w+y')'
((bd)(a + c'))'
((wy'+z)+(xz)')'

Draw the circuit that implements each of the following equations:

AB'+(C'+AD')+D
XY'+WZ+Y'
(AD'+BC+C'D)'
((W'X)'+(Y'+Z))'

In: Computer Science

In your own words, discuss the steps to improving customer experience.

In your own words, discuss the steps to improving customer experience.

In: Computer Science