Questions
Lab 7: 2D Arrays Project Goals The goals of this project are to: 1.       Get students...

Lab 7: 2D Arrays

Project Goals

The goals of this project are to:

1.       Get students familiar with 2D arrays

2.       Continue loop practice

Important Notes:

1.        Formatting: Make sure that you follow the precise recommendations for the output content and formatting: for example, do not change the text of the problem from “Enter the number of rows in your array: ” to “Enter the number of rows: ”. Your assignment will be auto-graded and any change in formatting will result in a loss in the grade.

2.       Comments: Header comments are required on all files and recommended for the rest of the program. Points will be deducted if no header comments are included.

Problem 1

Save your program as squaring.c

It’s better to be odd, so let’s square those values. Write a program which gets values into an array and then squares the odd values. The program should prompt the user to enter the number of rows -1[1] and columns they would like in an array. Then it should prompt the user to enter values to fill that array. It should iterate over all the values in the array and square any which are odd. Display those values back to the user.

The program should function as follows (items underlined are to be entered by the user):

Enter the number of rows in your 2D array: 2

Enter the number of columns in your 2D array: 2

Enter a value to save: 1

Enter a value to save: 2

Enter a value to save: 3

Enter a value to save: 4

1 2

9 4

Run your program again, testing it with different values.

Notes:

  • You know the range and step, which loop is best?
  • Know which variables to initialize!

[1]I think this should be ...rows... and not ...rows-1...

In: Computer Science

1. Implement the faster algorithm for integer multiplication in C++ as a function, called “multiply”, that...

1. Implement the faster algorithm for integer multiplication in C++ as a function, called “multiply”, that takes 2 unsigned integers and returns their multiplication as an unsigned integer.

2. Test your code in main.

Hints: Represent integers as strings.

Write a utility function that pads integers with zeros, this will be useful If the 2 integers differ in length In calculating ??10^? and (??+??) 10^(?/2)

In: Computer Science

Please use Java eclipse Find pair in an array with given sum Given an array of...

Please use Java eclipse

Find pair in an array with given sum

Given an array of integers A and an integer S, determines whether there exist two elements in the array whose sum is exactly equal to S or not.

Display 1 a pair is found in an array with matching sum S else 0.

Input
    6
    5
    1 -2 3 8 7

    Where,

  • First line represents integer S.
  • Second line represents the size of an array.
  • Third line represents array elements separated by single space.

Output
    1

For the given array, A[1] + A[3] = -2 + 8 = 6 which is equal to the given number S=6

In: Computer Science

URGENT write a c++ program which asks the user to enter a positive number which is...

URGENT
write a c++ program which asks the user to enter a positive number which is less than or equal to 9. Do not let the user continue until he or she enters a number within range. once a valid number is entered, multiply it by itself. if the resulting number is even, display a message with the number followed by the words even. If it is odd, display the number followed by the words is odd. must use a do-while loop

In: Computer Science

Files that are read by the computer are called ____ files. a. report b. serial c....

Files that are read by the computer are called ____ files.

a.

report

b.

serial

c.

input

d.

storage

The database for a pet supply company includes the following table, named tblCollar, that contains product data for pet collars. The ItemDesc and Color fields contain text. The ItemNum, Price, and Quantity fields contain numbers.

ItemNum

ItemDesc

Color

Price

Quantity

2358

leather studded collar

black

30.00

35

2693

leather collar

brown

25.00

25

3547

striped collar

red

20.00

75

3855

striped collar

blue

15.00

42

3764

striped collar

green

15.00

48

5782

solid collar

pink

12.00

36

5785

solid collar

red

12.00

10

5787

solid collar

blue

10.00

15

Which of the following statements would select the ItemDesc and Price fields from tblCollar for all records whose ItemDesc field begins with the word “leather” followed by zero or more characters?

a. SELECT ItemDesk FROM tblCollar

     WHERE ItemDesc LIKE 'leather %'

b. GET ItemDesc, Price FROM tblCollar

    WHERE ItemDesc LIKE 'leather %'

c. SELECT ItemDesc, Price FROM tblCollar

    WHERE ItemDesc LIKE 'leather %'

d. SELECT ItemDesc, Price FROM tblCollar

    WHERE ItemDesc LIKE leather %

The ____ statement is used for exception handling in a procedure.

a.

aggregate

b.

Try…Catch

c.

ORDER BY

d.

LINQ

A(n)____ function returns a single value from a group of values.

a.

WHERE

b.

Calculate

c.

Aggregate

d.

Parameter

Visual Basic’s auto-implemented properties feature enables you to ____.

a.

add validation code to the set block

b.

make the property ReadOnly

c.

make the property WriteOnly

d.

specify the property of a class in one line of code

are the actions to which an object can respond.

a.

Methods

b.

Behaviors

c.

Events

d.

Attributes

In: Computer Science

What is Rapid provisioning and what are the tools that we use to implement rapid provisioning?

What is Rapid provisioning and what are the tools that we use to implement rapid provisioning?

In: Computer Science

What is the relationship between REST and JSON?

What is the relationship between REST and JSON?

In: Computer Science

Infile and getline - how can I change this code to get the whole line from...

Infile and getline - how can I change this code to get the whole line from a text file? Right now it only gets the first word each time it reads. NUMBER can be any integer. This code gets strings that are in multiple lines from a text file. Some words are separated by whitespace and that makes the input wrong. It only works if there is only one word.

infile >> arrayOne[dive] >> arrayTwo[dive];

while (infile && dive< NUMBER)
{
dive++;
infile >> arrayOne[dive] >> arrayTwo[dive];
}

infile >> arrayOne[dive] >> arrayTwo[dive];
}

In: Computer Science

Create a query using query design. from the Clients table, display the client first name and...

Create a query using query design. from the Clients table, display the client first name and last name. From the Accounts Table, select the savings balance. Add appropriate grouping so the clients total retirement account savings balances are displayed. Add a sort so the highest total savings balances are displayed first.

In: Computer Science

Hard networking major Design a network for a private school that serves the learning side and...

Hard networking major

Design a network for a private school that serves the learning side and allows for easier communication between teachers and students and saves time.

In: Computer Science

Can someone explain to me whats happening for every method in this code and the breakdown...

Can someone explain to me whats happening for every method in this code and the breakdown of everything. I added the p2.h file for any reference needed and i need the Implementation of the tree ADT in the p2.h file explained and why it was implemented in that file and not p2.cpp.

p2.cpp

#include 
#include "p2.h"
#include "recursive.h"

using namespace std;

static int sum_helper(list_t list, int total) {
    if(list_isEmpty(list))
    {
                return total;
        }
     else
        return sum_helper(list_rest(list), total + list_first(list));
}
 
int sum(list_t list) {
    return sum_helper(list, 0);
}
 
static int product_helper(list_t list, int total) {
    if(list_isEmpty(list))
    {
                return total;
        }
    else
        return (product_helper(list_rest(list), total * list_first(list)));
}
 
int product(list_t list) {
    return product_helper(list, 1);
}
static int accumulate_helper(list_t list, list_t otherList, int result, int (*fn)(int, int), int identity) {
    if(list_isEmpty(list)) return identity;
    else if(list_isEmpty(otherList))return result;
    else
    {
        result = fn(list_first(otherList), result);
        return accumulate_helper(list, list_rest(otherList), result, fn, identity);
    }
}
 
int accumulate(list_t list, int (*fn)(int, int), int identity) {
    return accumulate_helper(list, list, identity, fn, identity);
}
 
static list_t reverse_helper(list_t list, list_t reverse) {
    if(list_isEmpty(list)) return reverse;
    else return reverse_helper(list_rest(list), list_make(list_first(list), reverse));
}
list_t reverse(list_t list)
{
    return reverse_helper(list, list_make());
}
static list_t append_helper(list_t first, list_t second, list_t reverse_first, list_t result) {
    if(list_isEmpty(first) && list_isEmpty(second)) return list_make();
    else if(list_isEmpty(first))return second;
    else if(list_isEmpty(second))return first;
    else
    {
        if(list_isEmpty(reverse_first))return result;
        else
        {
                 return append_helper(first, second, list_rest(reverse_first), list_make(list_first(reverse_first), result));
        }
    }
}
 
list_t append(list_t first, list_t second) {
    return append_helper(first, second, reverse(first), second);
}
static list_t filter_odd_helper(list_t list, list_t result) {
    if(list_isEmpty(list))return result;
    else
    {
            if (!(list_first(list)%2))
                return filter_odd_helper(list_rest(list), result);
            else return filter_odd_helper(list_rest(list), list_make(list_first(list), result));
    }
}
 
list_t filter_odd(list_t list) {
    return filter_odd_helper(list, list_make());
}
 
static list_t filter_even_helper(list_t list, list_t result) {
    if(list_isEmpty(list))return result;
                else
                {
            if (list_first(list)%2)
                {return filter_even_helper(list_rest(list), result);}
            else 
                {return filter_even_helper(list_rest(list), list_make(list_first(list), result));}
                }
}
 
list_t filter_even(list_t list) {
    return filter_even_helper(list, list_make());
}
 
static list_t filter_helper(list_t list1, list_t otherList, bool (*fn)(int), list_t result) {
    if(list_isEmpty(list1)) return result;
    else if(list_isEmpty(otherList)) return result;
    else if(fn(list_first(otherList)))
    {
          result = list_make(list_first(otherList), result);
          return filter_helper(list1, list_rest(otherList), fn, result);
    }
    else return filter_helper(list1, list_rest(otherList), fn, result);
}
 
list_t filter(list_t list, bool (*fn)(int)) {
    return reverse(filter_helper(list, list, fn, list_make()));
}
 
static list_t rotate_helper(list_t result, unsigned int n){
    if(n == 0 || list_isEmpty(result))return result;
    else return rotate_helper(reverse(list_make(list_first(result), reverse(list_rest(result)))), n-1);
}
 
list_t rotate(list_t list, unsigned int n)
{
    return rotate_helper(list, n);
}
 
static list_t insert_list_helper(list_t inFirst, list_t first, list_t fir1, list_t fir2, list_t second, unsigned int n2, unsigned int n1) {
      if (list_isEmpty(inFirst) || list_isEmpty(second) || n2==0)
     {
      if(n2==0)return append(second, inFirst);
          else return append(inFirst, second);
     } else {
        if (n1>0) 
          {return insert_list_helper(inFirst, list_rest(first), list_make(list_first(first),fir1),list_rest(first),second,n2,n1-1);}
            else
              return append(reverse(fir1), append(second, fir2));
      }
}
 
list_t insert_list(list_t first, list_t second, unsigned int n) {
       return insert_list_helper(first, first, list_make(), list_make(), second, n, n);
}
static list_t chop_helper(list_t numl, unsigned int n) {
      if(list_isEmpty(numl) || n==0) return numl;
      else return chop_helper(list_rest(numl), n-1);
}
list_t chop(list_t l, unsigned int n) {
    return reverse(chop_helper(reverse(l), n));
}
 
int fib(int n) {
    if(n==0) return 0;
    else if (n==1) return 1;
    else return (fib(n-1) + fib(n-2));
}
 
static int fib_tail_helper(int a, int counter, int b, int c) {
    if(a==0)return 0;
    else if(a==1)return 1;
    else
    {
         if(counter
else if(a%2) return c; 
         else return b;
    }
}
 
int fib_tail(int n) {
    if (!(n%2)) return fib_tail_helper(n, 0, 0, 1);
    else return fib_tail_helper(n, 1, 0, 1);
}
 
int tree_sum(tree_t tree)
{
     if(tree_isEmpty(tree)) return 0;
     else if(tree_isEmpty(tree_left(tree))&& tree_isEmpty(tree_right(tree)))return tree_elt(tree);
     else if(tree_isEmpty(tree_left(tree)))return (tree_elt(tree) + tree_sum(tree_right(tree)));
     else if(tree_isEmpty(tree_right(tree)))return (tree_elt(tree) + tree_sum(tree_left(tree)));
     else return(tree_elt(tree) + tree_sum(tree_left(tree)) + tree_sum(tree_right(tree)));
}
 
list_t traversal(tree_t tree)
{
      list_t ord_list = list_make();
 
      if(tree_isEmpty(tree))return ord_list;
                else
                {
           list_t elt = list_make(tree_elt(tree),list_make());
 
           if(!(tree_isEmpty(tree_right(tree))))
                ord_list = append(traversal(tree_right(tree)), elt);
           if(!(tree_isEmpty(tree_left(tree))))
                 ord_list = append(traversal(tree_left(tree)), elt);
 
           return ord_list;
                }
}
bool contained_by(tree_t A, tree_t B)
{
      if(tree_isEmpty(A)) return true;
      else if(!(tree_isEmpty(A) && tree_isEmpty(B))) return false;
                else
                {
            if(list_first(traversal(A)) == list_first(traversal(B)))
                  return contained_by(traversal(A), traversal(B));
            else
                  return(contained_by(tree_right(A), tree_right(B)) && contained_by(tree_left(A), tree_left(B)));
                }
}
 
tree_t insert_tree(int elt, tree_t tree)
{
      if(tree_isEmpty(tree))return tree_make(elt, tree_make(),tree_make());
                else
                {
            if(elt
return tree_make(tree_elt(tree), insert_tree(elt, tree_left(tree)), tree_right(tree)); 
            else
                  return tree_make(tree_elt(tree), tree_left(tree), insert_tree(elt, tree_right(tree)));
                }
}

the implementation in the p2.h file is below.

const unsigned int  tree_node_id = 0x45ee45ee;
const unsigned int  tree_empty_id = 0x56ff56ff;
struct tree_node 
{
    unsigned int       tn_id;    // Are we really a tree_node?
    int                tn_elt;   // This element
    struct tree_node  *tn_left;  // left subtree
    struct tree_node  *tn_right; // right subtree
};
static struct tree_node *
tree_checkValid(tree_t tree)
    // MODIFIES: cerr
    // EFFECTS: assert if tnp does not appear to be a valid tree, 
    //          writing an appropriate error message to cerr.
{
    struct tree_node *tnp = (struct tree_node *)tree;
 
    if ((tnp->tn_id != tree_node_id) && (tnp->tn_id != tree_empty_id)) {
        std::cerr << "Error: user pass invalid tree\n";
        //assert(0);
    }
    return tnp;
}
static void
tree_checkNonEmpty(tree_t tree)
{
  if (tree_isEmpty(tree))  {
      std::cerr << "Error: user pass empty tree\n";
     // assert(0);
    }
}
bool
tree_isEmpty(tree_t tree)
{
    struct tree_node *tnp = tree_checkValid(tree);
    return (tnp->tn_id == tree_empty_id);
}
 
tree_t
tree_make()
{
    struct tree_node *tnp = 0;
 
    try 
    {
      tnp = new struct tree_node;
    } 
        catch (std::bad_alloc a) 
    {
      //not_allocated();
    }
    tnp->tn_id = tree_empty_id;
    tnp->tn_left = NULL;
    tnp->tn_right = NULL;
    return tnp;
}
tree_t
tree_make(int elt, tree_t left, tree_t right)
{
    struct tree_node *tnp = 0;
    try 
    {
        tnp = new struct tree_node;
    } 
        catch (std::bad_alloc a) 
    {
        //not_allocated();
    }
 
    if (!tree_isEmpty(left)) 
    {
      tree_checkValid(left);
    }
    if (!tree_isEmpty(right)) 
    {
      tree_checkValid(right);
    }
    tnp->tn_id = tree_node_id;
    tnp->tn_elt = elt;
    tnp->tn_left = (struct tree_node *)left;
    tnp->tn_right = (struct tree_node *)right;
    return tnp;
}
int
tree_elt(tree_t tree)
{
    tree_checkNonEmpty(tree);
    struct tree_node *tnp = tree_checkValid(tree);
    return tnp->tn_elt;
}
tree_t
tree_left(tree_t tree)
{
    tree_checkNonEmpty(tree);
    struct tree_node *tnp = tree_checkValid(tree);
    return tnp->tn_left;
}
tree_t
tree_right(tree_t tree)
{
    tree_checkNonEmpty(tree);
    struct tree_node *tnp = tree_checkValid(tree);
    return tnp->tn_right;
}
static void
print_spaces(int spaces)
    // MODIFIES: cout
    // EFFECTS: prints n spaces
{
  while (spaces--) 
 {
      std::cout << "  ";
    }
}
static void
tree_print_internal(tree_t tree, int spaces)
    // MODIFIES: cout
    // EFFECTS: prints tree contents recursively, with newlines 
    //          for each node, with each level indented
{
  print_spaces(spaces);
    if (tree_isEmpty(tree)) 
    {
       std::cout << "( )\n";
    } else {
      std::cout << "(" << tree_elt(tree) << "\n";
        tree_print_internal(tree_left(tree), spaces+1);
        tree_print_internal(tree_right(tree), spaces+1);
        print_spaces(spaces);
        std::cout << " )\n";
    }
}
void
tree_print(tree_t tree)
{
  tree_print_internal(tree, 0);
}

In: Computer Science

Study the research papers and write a report on the following Agile Software Development Methods (ASDMs)...

  1. Study the research papers and write a report on the following Agile Software Development Methods (ASDMs)
  1. Adaptive Software Development (ASD)
  2. Dynamic System Development Method (DSDM)
  3. Crystal
  4. Feature Driven Development (FDD)
  1. Conduct a comparative analysis between Traditional Software Development Methods (TSDMs) and Agile Software Development Methods (ASDMs)
  2. Attach the Plagiarism report for your document

In: Computer Science

Below is some code for a rectangle class that needs to be completed. Add member function...

Below is some code for a rectangle class that needs to be completed. Add member function declarations to the class declaration and member function definitions below the declaration. For the accessor functions, you can add the definitions directly into the class declaration. The goal is to code the class so that it works wthout changing the main program

#include <iostream>
using namespace std;

// rectangle has a vertical height and horizontal width
// The class below is a rectangle. It has two private
// data members: height and width.
// TODO: Complete the class declaration and definition.
class rectangle {
public:
// TODO: declare a default constructor
// Make the height and width = 1.
  
// TODO: declare member function void add
// @param int height, int width

// TODO: delcare member function void set
// @param int height, int width
  
// TODO: declare member function void draw
  
// TODO: define accessor for width
  
// TODO: define accessor for height
  
private:
int width;
int height;
};

// TODO: define the default constructor that
// sets height and width to 1.
rectangle::rectangle()
{

}

// TODO: Implement add to increment the length
void rectangle::add(int h, int w)
{

}

// TODO: Implement set to overwrite the data members
void rectangle::set(int h, int w)
{

}

// TODO: Implement draw to draw a rectangle using '*' characters
void rectangle::draw()
{
  
  
}

// TODO: Don't forget to define getWidth and getHeight


int main()
{
// Declare 2 rectangles
rectangle r1, r2;
  
// Print the unit rectangle
cout << "r1 is " << r1.getHeight() << " x " << r1.getWidth() << endl;
  
// Set, print dimensions and draw
r1.set(4, 3);
cout << "r1 is " << r1.getHeight() << " x " << r1.getWidth() << endl;
r1.draw();
  
// Assign, increment, print dimensions and draw
r2 = r1;
r2.add(3, 4);
cout << "r2 is " << r2.getHeight() << " x " << r2.getWidth() << endl;
r2.draw();
  
return 0;
}

In: Computer Science

Find the closed form for the following series: 1 + x2 + x3 + … +...

Find the closed form for the following series: 1 + x2 + x3 + … + xn where x is constant and x > 1

In: Computer Science

in java Design and implement a class named Person and its two subclasses named Student and...

in java

Design and implement a class named Person and its two subclasses named Student and Employee. Make Faculty and Staff subclasses of Employee. A person has a name,address, phone number, and email address. A student has a class status (year 1,year 2,year 3,or year 4). An employee has an office, salary, and date hired. Use the Date class from JavaAPI 8 to create an object for date hired. A faculty member has office hours and a rank. A staff member has a title. Override the toString method in each class to display the class name and the person’s name.Design and implement all 5classes. Write a test program that creates a Person,Student,Employee,Faculty, and Staff, and iinvokes their toString()methods

In: Computer Science