Questions
Create a generic function max() in C++, to find maximum of 3 generic type arguments, then...

Create a generic function max() in C++, to find maximum of 3 generic type arguments, then test this function with char, int and float type.

In: Computer Science

Use Python to write the following code. Program Specifications: You are to design the following menu:...

Use Python to write the following code.

Program Specifications:

You are to design the following menu:

G] Get a number

S] Display current sum

A] Display current average

H] Display the current highest number

L] Display the current lowest number

D] Display all numbers entered

Q] Quit

If the user enters G, S, A, H, L, or D before selecting G the program needs to advise the user to go and enter a number first.

Rules for the Programmer (you)

  1. Source code must use a dynamic list to store all numbers
  2. Source code must have a function for each of the menu options above (I guess even for quit too]
  3. Source code must have reasonable comments
  4. Source code must not allow the user to do bad things (you can assume they will enter a number if they press G or if you want to figure it out, yell at the user if he or she does not enter a number)

In: Computer Science

What are templates in c++? How are they made? Write a program to explain function template.

What are templates in c++? How are they made? Write a program to explain function template.

In: Computer Science

Problem 2 Write a function (call it by your first name e.g. abc_trim) that takes a...

Problem 2

Write a function (call it by your first name e.g. abc_trim) that takes a list as argument , modifies it by removing the first and last two elements, and returns the new modified list e.g. if we call the function as katline_trim([1,4,6,8,11, 15]), we should get [4,6,8]. (Hint: Look at how we refer to list elements by their index and also how we use a negative number as index. You can also use a loop with the len() method

NB: Include python code, please. use spider

In: Computer Science

The Web has grown exponentially since its early days. Why? Please write at least 150 words.

The Web has grown exponentially since its early days. Why?

Please write at least 150 words.

In: Computer Science

In the assignment below please fix the errors in each code. The first code should have...

In the assignment below please fix the errors in each code. The first code should have a total of 3 erros. The second and third code should have 4 errors. Thanks

//DEBUG05-01
// This program is supposed to display every fifth year
// starting with 2017; that is, 2017, 2022, 2027, 2032,
// and so on, for 30 years.
// There are 3 errors you should find.
start
   Declarations
      num year
      num START_YEAR = 2017
      num FACTOR = 5
      num END_YEAR = 30
   year = START_YEAR
   while year <= END_YEAR
      output year
   endif
stop


//DEBUG05-02
// A standard mortgage is paid monthly over 30 years.
// This program is intended to output 360 payment coupons
// for each new borrower at a mortgage company.
// Each coupon lists the month number, year number,
// and a friendly mailing reminder.
// There are 4 errors here.
start
   Declarations
      num MONTHS = 12
      num YEARS = 30
      string MSG = "Remember to allow 5 days for mailing"
      num acctNum
      num yearCounter
   housekeeping()
   while acctNUm <> QUIT
      printCoupons()
   endwhile
   finish()
stop

housekeeping()
   print "Enter account number or ", QUIT, " to quit "
   input acctNum
return

printCoupons()
   while yearCounter <= YEARS
      while monthCounter <= MONTHS
         print acctNum, monthCounter, yearCounter, MSG
         monthCounter = monthCounter + 1
      endwhile
   endwhile
   output "Enter account number or ", QUIT, " to quit "
   input acctNum
return

finish()
   output "End of job"
return


//DEBUG05-03
// This program displays every combination of three-digits
// There are 4 errors here.
start
   Declarations
     num digit1 = 0
     num digit2 = 0
     num digit3 = 0
   while digit1 <= 9
      while digit2 <= 9
         while digit3 <= 9
            output digit1, digit2, digit3
            digit1 = digit1 + 1
         endwhile
         digit2 = digit2 + 1
      endwhile
      digit3 = digit3 + 1
   endwhile
stop

In: Computer Science

Write a JAVA program in eclipse (write comment in every line) that asks the user to...

Write a JAVA program in eclipse (write comment in every line) that asks the user to enter two numbers and an operator (+, -, *, / or %), obtain them from the user and prints their sum, product, difference, quotient or remainder depending on the operator. You need to use OOP techniques (objects, classes, methods….). This program must be place in a loop that runs 3 times.

In: Computer Science

How can I get the days to print in order (Monday, Tuesday, Wednesday etc) def summarize_by_weekday(expense_list):...

How can I get the days to print in order (Monday, Tuesday, Wednesday etc)

def summarize_by_weekday(expense_list):
"""
Requirement 3 to display the total amount of money spent on each weekday, aggregated per day.
That is, display “Monday: $35”, “Tuesday: $54”, etc., where $35 is the sum of dollar amounts for a
ll Mondays present in the data file, $54 is the sum of dollar amounts for all Tuesdays present in the data file,
and so on.
:param expense_list:
:return: None
"""
  weekday_spent_dict={}
for expense in expense_list:
if weekday_spent_dict.get(expense[0])==None:
weekday_spent_dict[expense[0]]=expense[1]
else:
weekday_spent_dict[expense[0]] += expense[1]
for day in sorted(weekday_spent_dict.keys()):
print('{0}: ${1:5.2f}'.format(day,weekday_spent_dict.get(day)))

output is:

Enter 1 display all of the expense records
2 to display all of the expense records for a particular category
3 to display the total amount of money spent on each weekday, aggregated per day
0 to quit.3
Friday: $94.90
Monday: $40.75
Saturday: $201.38
Sunday: $305.44
Thursday: $276.49
Tuesday: $14.85
Wednesday: $14.85

I want it to print:

Monday

Tuesday

Wednesday

etc..

def get_data(fname):
fileObj = open(fname)
lines = fileObj.readlines()
expense_list = []

for line in lines[1:]: # for lines starting at 2 (excluding 1 because it is the
line_items = line.strip().split(",") # strip removes the newline character
expense_list.append([line_items[0], float(line_items[1]), line_items[2]])

return expense_list

In: Computer Science

import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Scanner; public class Main { static Scanner sc=new Scanner(System.in);...

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

import java.util.Scanner;

public class Main {

static Scanner sc=new Scanner(System.in);

static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

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

// TODO code application logic here

System.out.print("Enter any String: ");

String str = br.readLine();

System.out.print("\nEnter the Key: ");

int key = sc.nextInt();

String encrypted = encrypt(str, key);

System.out.println("\nEncrypted String is: " +encrypted);

String decrypted = decrypt(encrypted, key);

System.out.println("\nDecrypted String is: "

+decrypted); System.out.println("\n");

}

public static String encrypt(String str, int key)

{ String encrypted = "";

for(int i = 0; i < str.length(); i++) {

int c = str.charAt(i);

if (Character.isUpperCase(c)) {

c = c + (key % 26);

if (c > 'Z')

c = c - 26;

}

else if (Character.isLowerCase(c)) {

c = c + (key % 26);

if (c > 'z')

c = c - 26;

}

encrypted += (char) c;

}

return encrypted;

}

public static String decrypt(String str, int key)

{ String decrypted = "";

for(int i = 0; i < str.length(); i++) {

int c = str.charAt(i);

if (Character.isUpperCase(c)) {

c = c - (key % 26);

if (c < 'A')

c = c + 26;

}

else if (Character.isLowerCase(c)) {

c = c - (key % 26);

if (c < 'a')

c = c + 26;

}

decrypted += (char) c;

}

return decrypted;

}

}

What is the Caesar cipher?

Write the algorithm of the illustrated program?

In: Computer Science

C++ Question Write a code for :- public List Palindrome(); //Check whether a given singly linked...

C++ Question

Write a code for :-

public List Palindrome();

//Check whether a given singly linked list is palindrome or not.

Input:

a -> b-> NULL

a -> b -> a-> NULL

s -> a -> g -> a -> r-> NULL r -> a -> d -> a -> r-> NULL

Output:

not palindrome palindrome

not palindrome palindrome

Note:- Code should work on MS-Visual Studio 2017 and provide outputs with code

In: Computer Science

IMPLEMENT IN JAVA PLEASE I NEED THIS DONE ASAP Question 1 (25pt) Dynamic Programming – Coin...

IMPLEMENT IN JAVA PLEASE I NEED THIS DONE ASAP

Question 1 (25pt) Dynamic Programming – Coin Change

Design algorithm for the coin change problem using dynamic programming approach. Given coin denominations by value: c1 < c2 < … < cn, and change amount of x, find out how to pay amount x to customer using fewest number of coins.

Your algorithm needs to work for ANY coin denomination c1 < c2 < … < cn, and ANY change amount of x. For example, given coin denominations 1, 5, 10, 25, x=78, the solution is {3 coins of 25 and 3 coins of 1, total 6 coins}.

NEED TO DO ALL 3 PARTS

• Present your algorithm in pseudo code.

• Trace your algorithm and show how it works on a small example, show the step-by-step process and the final result.

• Analyze the time complexity of the algorithm and present the result using order notation.

In: Computer Science

Hide Assignment Information Instructions In this assignment, you will be practicing the Java OOP skills we've...

Hide Assignment Information

Instructions

In this assignment, you will be practicing the Java OOP skills we've learned this week in implementing a customized mutable Array class. Please read the following requirements carefully and then implement your own customized Array class:

=== 1) Basic (100' pts total) ===

Your Array class must provide the following features:

--1.1) (20' pts) Two constructors. One takes the input of the initialized capacity (int) and create the underlying array with that capacity; the other takes no input and creates an array that can hold a single element by default (that is, init capacity == 1);

--1.2) (20' pts) Getters and setters and basic methods we discussed during the class including: getCapacity(), getSize(), set(int index), get(int index), isEmpty();

--1.3) (20' pts) CRUD operations we discussed during the class including: add(int index), addLast(), addFirst(), remove(int index), removeLast(), removeFirst(), removeElement(int target), removeAll(int target);

--1.4) (20' pts) Supports generic types;

--1.5) (20' pts) Mutable, that is when add element exceeding its capacity, it can resize to accommodate the change.

=== 2) Bonus (20' pts total) ===

2.1) (10' pts) Implement a (private or public) swap(int a, int b) method that swaps the two elements in the index a and b if a and b are both admissible; also a public reverse() method that reverses the order of stored elements in-place (means, no additional spaces are allocated).

2.2) (10' pts) A public void sort() method sorts the stored elements in ascending order inO(nlog(n)) time.

[hint]: Quicksort or Merge sort

In: Computer Science

Multidimensional Arrays Design a C program which uses two two-dimensional arrays as follows: - an array...

Multidimensional Arrays
Design a C program which uses two two-dimensional arrays as follows:
- an array which can store up to 50 student names where a name is up to 25 characters long
- an array which can store marks for 5 courses for up to 50 students
The program should first obtain student names and their corresponding marks for a requested number of students from the user. Please note that the program should reject any number of students that is requested by the user which is greater than 50. The program will compute the average mark for each course and then display all students and their marks, as well as the average mark for each course.
A sample output produced by the program is shown below, if assumed that the user entered marks for 4 students. Please note that the computation of the average mark for each course should use type casting.


Student PRG DGS MTH ECR GED
Ann Smart 93 85 87 83 90
Mike Lazy 65 57 61 58 68
Yo Yo 78 65 69 72 75
Ma Ma 84 79 83 81 83
AVERAGE 80.0 71.5 75.0 73.5 79.0


It is required to submit your source code file, i.e. Lab5.c file as well as a file with your program's run screen captures.

In: Computer Science

Multidimensional Arrays Design a C program which uses two two-dimensional arrays as follows: - an array...

Multidimensional Arrays
Design a C program which uses two two-dimensional arrays as follows:
- an array which can store up to 50 student names where a name is up to 25 characters long
- an array which can store marks for 5 courses for up to 50 students
The program should first obtain student names and their corresponding marks for a requested number of students from the user. Please note that the program should reject any number of students that is requested by the user which is greater than 50. The program will compute the average mark for each course and then display all students and their marks, as well as the average mark for each course.
A sample output produced by the program is shown below, if assumed that the user entered marks for 4 students. Please note that the computation of the average mark for each course should use type casting.


Student PRG DGS MTH ECR GED
Ann Smart 93 85 87 83 90
Mike Lazy 65 57 61 58 68
Yo Yo 78 65 69 72 75
Ma Ma 84 79 83 81 83
AVERAGE 80.0 71.5 75.0 73.5 79.0


It is required to submit your source code file, i.e. Lab5.c file as well as a file with your program's run screen captures.

In: Computer Science

Please complete it in C++ Part 1: Stack Create a New Project and give your project...

Please complete it in C++

Part 1: Stack

  1. Create a New Project and give your project a name, say Lab6a.
  2. Download the given source files StackArr.h and StackArr.cpp from Moodle and save them to your Lab6a folder. Also import them to your project.
  3. Add a source file to your project, called StackMain.cpp and implement your program according to the following:
    1. Prompt the user to input a program filename.
    2. Open the file and check if every right brace (i.e. }), bracket (i.e. ]), and parenthesis (i.e. )) in the file correspond to its left counterpart or not.
    3. If the program file passed the checking, output "The code is correct". Otherwise, output "The code is incorrect".

The algorithm for checking is as follows:

  1. Make an empty stack
  2. Read characters until the end of program file
    1. if the character is an opening symbol, push it onto the stack;
    2. if it is a closing symbol and if the stack is empty, output "Error: Empty stack";
    3. otherwise, pop the stack. If the symbol popped is not the corresponding opening symbol, output "Error: Not equal".

At the end of the file, if the stack IS NOT EMPTY, output "The code is incorrect". Otherwise, output "The code is correct".

Use the provided files, testfile1.txt and testfile2.txt to test your program. The code file testfile1.txt is correct, while the code file testfile2.txt is incorrect.

Useful code:

#include <fstream>

string readFile() {

     string tempString = "";

     string filename;

    

     cout << "Input file name: ";

     cin >> filename;

     ifstream inputFile(filename);

    

     // Prompt user again if wrong filename received

     while (!inputFile.good()) {

          cout << "Wrong file name, input again please: ";

          cin >> filename;

          inputFile.open(filename);

     }

    

     // Append all lines from the file into a long string

     while ((!inputFile.eof())) {

          string str;

          getline(inputFile, str);

          tempString += str;

     }

    

     return tempString;

}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#include "StackArr.h"
#include <string>
#include <iostream>

using namespace std;

StackArr::StackArr(int size) {
   maxTop = size;
   values = new char[size];
   stackTop = -1;
}

StackArr::~StackArr() {
   delete[] values;
}

bool StackArr::isEmpty() const {
   return stackTop == -1;
}

bool StackArr::isFull() const {
   return stackTop == maxTop;
}

void StackArr::push(const char& x) {
   if (isFull())
       cout << "Error! The stack is full!" << endl;
   else
       values[++stackTop] = x;
}

char StackArr::pop() {
   if (isEmpty()) {
       cout << "Error! The stack is empty!" << endl;
       return -1;
   }
   else
       return values[stackTop--];
}

char StackArr::top() const {
   if (isEmpty()) {
       cout << "Error! The stack is empty!" << endl;
       return -1;
   }
   else
       return values[stackTop];
}

void StackArr::displayStack() const {
   cout << "Top -->";
   for (int i = stackTop; i >= 0; i--)
       cout << "\t|\t" << values[i] << "\t|" << endl;
   cout << "\t|---------------|" << endl;
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#include "StackArr.h"
#include <string>
#include <iostream>

using namespace std;

StackArr::StackArr(int size)
   maxTop = size;
   values = new char[size];
   stackTop = -1;
}

StackArr::~StackArr() {
   delete[] values;


bool StackArr::isEmpty() const {
   return stackTop == -1;
}

bool StackArr::isFull() const {
   return stackTop == maxTop;
}

void StackArr::push(const char& x) {
   if (isFull())
       cout << "Error! The stack is full!" << endl;
   else
       values[++stackTop] = x;
}

char StackArr::pop() {
   if (isEmpty()) {
       cout << "Error! The stack is empty!" << endl;
       return -1;
   }
   else
       return values[stackTop--];
}

char StackArr::top() const {
   if (isEmpty()) {
       cout << "Error! The stack is empty!" << endl;
       return -1;
   }
   else
       return values[stackTop];
}

void StackArr::displayStack() const {
   cout << "Top -->";
   for (int i = stackTop; i >= 0; i--)
       cout << "\t|\t" << values[i] << "\t|" << endl;
   cout << "\t|---------------|" << endl;
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//StackArr.h

#ifndef STACKARR_H
#define STACKARR_H

class StackArr {
private:
   int maxTop;
   int stackTop;
   char *values;

public:
   StackArr(int);
   ~StackArr();
   bool isEmpty() const;
   bool isFull() const;
   char top() const;
   void push(const char& x);
   char pop();
   void displayStack() const;
};

#endif
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////StackArr.cpp

#include "StackArr.h"
#include <string>
#include <iostream>

using namespace std;

StackArr::StackArr(int size) {
   maxTop = size;
   values = new char[size];
   stackTop = -1;
}

StackArr::~StackArr() {
   delete[] values;
}

bool StackArr::isEmpty() const {
   return stackTop == -1;
}

bool StackArr::isFull() const {
   return stackTop == maxTop;
}

void StackArr::push(const char& x) {
   if (isFull())
       cout << "Error! The stack is full!" << endl;
   else
       values[++stackTop] = x;
}

char StackArr::pop() {
   if (isEmpty()) {
       cout << "Error! The stack is empty!" << endl;
       return -1;
   }
   else
       return values[stackTop--];
}

char StackArr::top() const {
   if (isEmpty()) {
       cout << "Error! The stack is empty!" << endl;
       return -1;
   }
   else
       return values[stackTop];
}

void StackArr::displayStack() const {
   cout << "Top -->";
   for (int i = stackTop; i >= 0; i--)
       cout << "\t|\t" << values[i] << "\t|" << endl;
   cout << "\t|---------------|" << endl << endl;
  
}

In: Computer Science