3. Are the following languages A and B over the alphabet Σ = {a, b, c, d} regular or nonregular? • For a language that is regular, give a regular expression that defines it. • For a nonregular language, using the pumping lemma prove that it is not regular. (a) A = {d 2j+1c k+1 | j ≥ k ≥ 0} · {c r+2b 2s+3 | r ≥ 0 and s ≥ 0} (b) B = {a 2j+2b k+3c j+1 | j ≥ 1 and k ≥ 1} · {d m+3 | m ≥ 0} Above “·” stands for language concatenation. Hints: The languages A and B are each expressed as concatenation of two components. If one (or both) of the components is non-regular, this does not imply anything about the non-regularity of the concatenation. If trying to show that a language C is non-regular, we have to apply the pumping lemma to the entire language C (and not to the individual components of the concatenation). On the other hand, if trying to show that C is regular, we can find regular expressions for the two components separately and then use the concatenation operation.
In: Computer Science
5. (20%) Suppose we have an array int a [8] = {1, 2, 3, 5, 6};
and we also have a linked list L of 5 entries 1 -> 2 -> 3
-> 5 -> 6, where 1 is the first in the linked list L,
followed by 2 etc. We want to put a new item 4 between 3 and 5 in
the array a and in the linked list L
(a) Explain in plain English how you do that in the array a. You
may have to shift items right (or left?) Do you use a loop like a
for loop? You can write some C / C++ / C# / Java code etc. to
convince me, but the code does not have to run.
(b) Explain in plain English how you do that in the linked list L.
How do you change the link from 3 to 5 in the original list L? You
can write some code or pseudo code to convince me.
In: Computer Science
Scenario: you are designing PlayMe.io – a mobile app to enter, manage, and play music playlists.
In: Computer Science
For java program.
for Loop
do Loop
roll = rand.nextInt(6) + 1;
System.out.println(" Roll = " + roll);
ctr++;
Here is a sample output display:
The rolls are:
Roll = 3
Roll = 1
Roll = 4
Roll = 6
Roll = 4
Add a loop structure using the while loop and then add a for loop. The program should include 3 loops that do the same thing. What is the “best” loop structure to use for this problem and why?
In: Computer Science
(C++ only please)
Write a function called maximum that takes an array of double values as a parameter and returns the largest value in the array. The length of the array will also be passed as a parameter. (Note that the contents of the array should NOT be modified.)
Write a function called printReverse that takes an array of characters and the length of the array as parameters. It should print the elements of the array in reverse order. The function should not return anything. (Note that the contents of the array should NOT be modified.)
Write a function called triple that takes an array of integers as a parameter as well as the length of the array. It should triple each value in the array. The function should not return anything. (Note that the contents of the array WILL be modified.)
Write a program (i.e. a main function) that simply calls each of the 3 functions above. For each function, initialize an array with arbitrary values, then call the corresponding function and display the result. For the maximum function, you will initialize an array of double values. Then you will call the maximum function, passing that array of doubles, and print the result. For the printReverse function, you will initialize an array of characters. Then you will call the printReverse function to print the array of characters in reverse order. Finally, you will initialize an array and call the triple function. For the triple function, you will need to print the entire array after the function has been called to show that each element was indeed tripled. (Hint: Your main function should consist of about 8 lines of code.)
In: Computer Science
Language:C++
NEEDS TO WORK IN VISUAL BASIC
error on line 41 expression must have a constant value
#include
using namespace std;
//function declaration
void EnterRents(int*, int);
void displayRents(int*, int);
void selectionSort(int*, int);
int sumRents(int* temp, int size)
{
int sum = 0;
for (int i = 0; i < size; i++)
{
sum += *(temp + i);
}
return sum;
}
void Displaymemory(int* temp, int size)
{
/*int memory;
memory=sizeof(temp)*size;
cout< for (int i = 0; i < size; i++)
{
cout << &temp[i] << " ";
}
}
//main drive
int main()
{
int n;
char c;
cout << "Enter a for enter the rents amounts" <<
endl;
cout << "Enter b to display rents amounts" <<
endl;
cout << "Enter c to sort the rents amounts" <<
endl;
cout << "Enter d to total rents amounts" << endl;
cout << "Enter e to display memory alloaction" <<
endl;
cout << "Enter f to exit" << endl;
cout << "Enter the number of amount items stored in Amout
array " << endl;
cin >> n;
int arr[n];
//while statement with switch case to call declared function
while (1)
{
cout << endl;
cout << "Enter your choice" << endl;
cin >> c;
switch (c)
{
case 'a':
cout << "Enter the " << n << " no of Rents
amount" << endl;
EnterRents(arr, n);
break;
//Other switch cases
case 'b':
cout << "Display Rents" << endl;
displayRents(arr, n);
break;
case 'c':
cout << "sort Rents amounts" << endl;
selectionSort(arr, n);
cout << "sorted elemnts are" << endl;
displayRents(arr, n);
break;
case 'd':
cout << "Total Rents" << endl;
cout << sumRents(arr, n) << endl;
break;
case 'e':
cout << "Display memoryLocation" << endl;
Displaymemory(arr, n);
break;
case 'f':
cout << "f entered by user to exit" << endl;
exit(1);
default:
cout << "Invalid input.";
break;
}
}
return 0;
}
//function definition
void EnterRents(int* arr, int size)
{
for (int i = 0; i < size; i++)
{
cin >> arr[i];
}
}
void displayRents(int* arr, int n)
{
for (int i = 0; i < n; i++)
{
cout << *(arr + i) << " ";
}
}
//void selectionSort(int*,int)
void selectionSort(int* pointer, int size)
{
int* i, * j, swap;
int* end = NULL;
if (size < 2 || pointer == NULL)
return;
end = pointer + size - 1;
for (i = pointer; i < end; i++)
{
for (j = i + 1; j <= end; j++)
{
if (*j < *i)
{
swap = *i;
*i = *j;
*j = swap;
}
}
}
}
In: Computer Science
Which statement is true of symmetric encryption?
Question 2 options:
|
|||
|
|||
|
|||
|
Which type of access control is used to protect systems from unauthorized access?
Question 4 options:
|
|||
|
|||
|
|||
|
In: Computer Science
why my code for mergesort always wrong ?
void Merge(vector<int>& data, int p, int q,
int r)
{
int n1 = q - p + 1;
int n2 = r - q;
vector<int>left(n1);
vector<int>right(n2);
for(int i = 0; i < n1; i++)
{
left[i] = data[p + i];
}
for(int j = 0; j < n2; j++)
{
right[j] = data[q+j+1];
}
int i = 0;
int j = 0;
for(int k = p; k <= r; k++)
{
if(left[i] <= right[j])
{
data[k] = left[i];
i += 1;
}
else
{
data[k] = right[j];
j += 1;
}
}
}
void MergeSort(vector<int>& data, int p, int
r)
{
if(p<r)
{
int q = (p+r)/2;
MergeSort(data, p, q);
MergeSort(data, q+1, r);
Merge(data, p, q, r);
}
In: Computer Science
This assignment will require you to write a 300-word APA style essay paper with references on the topic of Net-Neutrality
The paper should focus specifically on the following:
What is Net-Neutrality and your position on the subject - for or against and why?
How does Net-Neutrality impact digital forensics?
Should Internet Service Providers (ISP's) be liable for computer crimes committed on their networks?
Does Net-Neutrality support freedom of speech - if yes or no, why?
In: Computer Science
Course name : Algorithm and Data Structure-I
Write a brief note about dependent structure.
Compare between tree and qraph.
Explain What we means by "Data encapsulation"? And give example.
Explain the concept of interface in java with example.
Calculate T(n) and Big O notation for the following algorithm:
Initialize sum to 0.
Initialize index variable i to 0
While i<n do the following
Calculate and return mean = sum / n .
*Please answer these with no pics or hand writing
In: Computer Science
Cyber security
Cryptography Homework
Part 1: Find good encryption solutions
In: Computer Science
In: Computer Science
Hello I have this error in the code, I do not know how to fix it. It is written in C++ using a Eclipse IDE
Error: libc++abi.dylib: terminating with uncaught exception of type std::out_of_range: basic_string
bus.h
===========
#pragma once
#include
using namespace std;
class Bus {
private:
string BusId; // bus ID
string Manufacturer; // manufacturer of the bus
int BusCapacity; // bus capacity
int Mileage; // mileage of bus
char Status; // current status of the bus
public:
Bus(string bus_id, string manufac, int cap, int
mileage, char status); // constructor
~Bus(); // destructor
// getter methods
string getBusId(); // return bus id
string getManufacturer(); // return manufacturer of
the bus
int getBusCapacity(); // return bus capacity
int getMileage(); // return bus mileage
char getStatus(); // return current status of
bus
// setter methods
void setStatus(char s); // set the given status to the
bus status
};
============
bus.cpp
============
#include "bus.h"
Bus::Bus(string bus_id, string manufac, int cap, int mileage,
char status) {
// initialize member variables
BusId = bus_id;
Manufacturer = manufac;
BusCapacity = cap;
Mileage = mileage;
Status = status;
}
Bus::~Bus() {
// delete bus object
}
string Bus::getBusId() {
return BusId;
}
string Bus::getManufacturer() {
return Manufacturer;
}
int Bus::getBusCapacity() {
return BusCapacity;
}
int Bus::getMileage() {
return Mileage;
}
char Bus::getStatus() {
return Status;
}
void Bus::setStatus(char s) {
Status = s;
}
================
functions.h
================
#pragma once
#include "bus.h"
#include
// print column header
void displayCH();
// print bus data
void printId(string id);
void printMfc(string mfc);
void printCap(int cap);
void printMileage(int mileage);
void printStatus(char s);
void printEndl();
=============
functions.cpp
=============
#include "functions.h"
void displayCH() {
cout <<
"================================================================="
<< endl;
cout << setw(10) << left << "Bus
ID";
cout << setw(20) << left << "Bus
Manufacturer";
cout << setw(10) << right << "Bus
Capacity";
cout << setw(10) << right <<
"Mileage";
cout << setw(10) << right <<
"Status" << endl;
cout <<
"================================================================="
<< endl;
}
void printId(string id) {
cout << setw(10) << left <<
id;
}
void printMfc(string mfc) {
cout << setw(20) << left <<
mfc;
}
void printCap(int cap) {
cout << setw(10) << right <<
cap;
}
void printMileage(int mileage) {
cout << setw(10) << right <<
mileage;
}
void printStatus(char s) {
cout << setw(10) << right << s
<< endl;
}
void printEndl() {
cout << "---end of list---" << endl;
}
===========
main.cpp
===========
#include "functions.h"
#include
#include
#include
int main() {
vector buses; // stores a list of buses created
// read input record
// create file stream object to read data
ifstream file("input.txt");
string line; // stores input record for a bus
while (!file.eof()) {
getline(file, line); // read input
line by line
// first 5 character in record are
bus id
string id = line.substr(0,
5);
// remove id from line
line = line.substr(5);
// last charater in record is
status
char status = line.at(line.length()
- 1);
// remove last charater from
line
line =
line.substr(0,line.length()-1);
// now last 7 digit are mileage of
bus
string miles =
line.substr(line.length() - 7);
// remove last 7 character from
line
line = line.substr(0, line.length()
- 7);
// convert string to int
int mileage = stoi(miles);
// now last 3 digit in the line are
bus capacity
int cap =
stoi(line.substr(line.length() - 3));
// remove last 3 character from
line
line = line.substr(0, line.length()
- 3);
// remainig data in line is
manufaturer
// create a bus object
Bus
b(id,line,cap,mileage,status);
// add bus to the list
buses.push_back(b);
}// end of while loop
// close file stream as done reading data
file.close();
// get user input
string input = ""; // stores user input
while (input != "X") {
// promt user for input
cout << "Enter transaction
code (D=display, L=list a bus, C=change, X=exit)" <<
endl;
getline(cin, input); // get input
from user
// read input
if (input.substr(0,1) == "D")
{
//display all
bus object
displayCH();
for (int i = 0;
i < buses.size(); i++) {
printId(buses.at(i).getBusId()); // print bus
id
printMfc(buses.at(i).getManufacturer()); //
print bus manufacturer
printCap(buses.at(i).getBusCapacity()); // print
bus capacity
printMileage(buses.at(i).getMileage()); // print
bus mileage
printStatus(buses.at(i).getStatus()); // print
current status of the bus
}
printEndl();
}
// check if input is exit
else if (input.substr(0, 1) == "X")
{
// break the
loop
break;
}
// check if input is list
else if (input.substr(0, 1) == "L")
{
// check for bus
id
string id =
input.substr(2);
// create a flag
to indicate if bus found
bool found =
false;
for (int i = 0;
i < buses.size(); i++) {
if (buses.at(i).getBusId().compare(id) == 0)
{
// print header
displayCH();
// print bus data
printId(buses.at(i).getBusId()); // print bus id
printMfc(buses.at(i).getManufacturer()); // print bus
manufacturer
printCap(buses.at(i).getBusCapacity()); // print bus capacity
printMileage(buses.at(i).getMileage()); // print bus mileage
printStatus(buses.at(i).getStatus()); // print current status of
the bus
printEndl(); // print end
line
// set flag to true
found = true;
}
}// checked all
buses data
if (!found)
{
// print error
cout << "Not found" << endl;
}
}
// check if input is change
else if (input.substr(0, 1) == "C")
{
// check for bus
id
string id =
input.substr(2,5);
// create a flag
to indicate if bus found
bool found =
false;
for (int i = 0;
i < buses.size(); i++) {
if (buses.at(i).getBusId().compare(id) == 0)
{
// get current status of
bus
char status =
input.at(8);
// change status of bus
buses.at(i).setStatus(status);
// print message of change
done
cout << "Change
successful" << endl;
// set flag to true
found = true;
}
}// checked all
buses data
if (!found)
{
// print error
cout << "Not found" << endl;
}
}
else {
// print error
in input
cout <<
"Invalid Input!" << endl;
}
}
// print goodbuy message
cout << "Thank you and have a nice day!"
<< endl;
return 0;
}
==========
input.txt
==========
A1234Gillig 0750001000a
B2345Flxible 1100011235a
C3456Daimler 0350002500a
D4567MAN 0900125000a
E5678General Mo1400150000a
F6789Gillig 0480002000r
G7890Gillig 0480003000m
H8901Flxible 1100012330m
I9012Flxible 1090015500a
J0123Daimler 0350002750r
In: Computer Science
Write a python programA3) Lambda Expressions. Use lambda expression to sort the list ["democratic", "republican", "equal", "python", "break", "two", "ruby"] by: a) the last 2 characters of each list item in reverse order b) create new list from list above where each item has only 3 characters and first one is capitalized. For example, the list item = "democratic" will transform into "Dem". Apply alphabetically sorting to the new list.
In: Computer Science
Write a program which shows how two-dimensional arrays which contain multiple copies of your id number and age are passed to methods. Explain in your own words each method and class used in the program.
My id number is 12133149
In: Computer Science