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
The algorithm for checking is as follows:
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
Remove inline style to an external file
<!DOCTYPE html>
<html>
<head>
<title>PROBLEM</title>
</head>
<body>
<form>
<table style="color:white;background-color:blue;border:solid
black 7px;border-radius:25px;">
<tr><th colspan="2"
style="color:white;background-color:black;border:solid black
2px;outline:solid black 2px;">SQUARE
PROBLEM</th></tr>
<tr> <td><label>Enter
side:</label></td><td> <input type="text"
style="background-color:#DEDEE6;border:4px solid red;"/>
</td> </tr>
<tr>
<td><label>Area:</label></td><td>
<input type="text" readonly
style="background-color:#DEDEE6;border:4px solid yellow;"/>
</td> </tr>
<tr>
<td><label>Perimeter:</label></td>
<td> <input type="text" readonly
style="background-color:#DEDEE6;border:4px solid yellow;"/>
</td> </tr>
<tr>
<td colspan="2" >
<center>
<input type="button" value="Area"
style="color:white;background-color:black;border:1px solid
red;"/>
<input type="button" value="Perimeter"
style="color:white;background-color:black;border:1px solid
white;"/>
<input type="button" value="Both"
style="color:white;background-color:black;border:1px solid
red;"/>
<input type="button" value="Clear"
style="color:white;background-color:black;border:1px solid
white;"/>
</center>
</td>
</tr>
</table>
</form>
</body>
</html>
In: Computer Science
The use of list or any other data type not allowed only string and string methods .Hint: Depending on how you plan to solve this problem, accumulator variable initialized as an empty string may help in this question. Write a function called weaveop, that takes a single string parameter (s) and returns a string. This function considers every pair of consecutive characters in s. It returns a string with the letters o and p inserted between every pair of consecutive characters of s, as follows. If the first character in the pair is uppercase, it inserts an uppercase O. If however, it is lowercase, it inserts the lowercase o. If the second character is uppercase, it inserts an uppercase P. If however, it is lowercase, it inserts the lowercase p. If at least one of the character is not a letter in the alphabet, it does not insert anything between that pair. Finally, if s has one or less characters, the function returns the same string as s. Do dir(str) and check out methods isalpha (by typing help(str.isalpha) in Python shell), and isupper
>>> weaveop("aa") 'aopa'
>>> weaveop("aB") 'aoPB'
>>> weaveop("ooo") 'oopoopo'
>>> weaveop("ax1") 'aopx1'
>>> weaveop("abcdef22") 'aopbopcopdopeopf22'
>>> weaveop("abcdef22x") 'aopbopcopdopeopf22x'
>>> weaveop("aBCdef22x") 'aoPBOPCOpdopeopf22x'
>>> weaveop("x") 'x'
>>> weaveop("123456") '123456'
In: Computer Science
Computer dynamics is a microcomputer software development company that has a 300-computer network. The company is located in three adjacent five-story buildings in an office park with about 100 computers in each building. The LANs in each building are similar, but one building has the data center in the second floor. There are no other office locations. Please refer to the network architecture components in Figure 6-1 of the textbook, and identify the key network architecture components in the design of the enterprise network. Refer to Chapter 6 and discuss how you would go about designing the physical network. You may assume that the campus does not need WAN connectivity.
Dear All,
This week; you are going to Design a "Real World" scenario Network as specified above.
Please start with a blue print design using "Visio" software Try first to think about the "Hardware-Devices" such as Wired Switches, Routers, Cables and Wireless Access Points, Wireless Repeaters (Extenders). See and estimate the number of users for your network, and put no more than 15 users/Access points for the Wireless connection, and select the wired switches to have X number of ports so that the over-ll wired users would be efficiently covered.
In: Computer Science
void append(Node list1, Node list2)
If the list1 is {22, 33, 44, 55} and list2 is {66, 77, 88, 99} then append(list1, list2) will change list1 to {22, 33, 44, 55, 66, 77, 88, 99}. (5 Marks: 1mark for each correct step)
int sum(Node list)
If the list is {25, 45, 65, 85} then sum(list) will return 220. (5 Marks: 1mark for each correct step)
L.add(50);
L.add(60);
L.addFirst(10);
L.addLast(100);
L.set(1, 20);
L.remove(1);
L.remove(2);
L.removeFirst();
L.removeLast(); (10 Marks: 1 mark for each correct answer)
L.addFirst(10);
Array and Linked List
In: Computer Science
Please complete it in C++
Part 2: Queue
The following shows a number of program's sample input / output sessions.
Input a string: aibohphobia
aibohphobia is a palindrome
Input a string: level
level is a palindrome
Input a string: desmond
desmond is not a palindrome
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////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
#pragma once
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////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;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////QueueArr.h
#ifndef QUEUEARR_H
#define QUEUEARR_H
class QueueArr {
private:
int front;
int back;
int counter;
int maxSize;
char* values;
public:
QueueArr(int);
~QueueArr();
bool isEmpty() const;
bool isFull() const;
bool enqueue(char x);
char dequeue();
void displayQueue() const;
};
#endif
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////QueueArr.cpp
#include "QueueArr.h"
#include <string>
#include <iostream>
using namespace std;
QueueArr::QueueArr(int size) {
values = new char[size];
maxSize = size;
front = 0;
back = -1;
counter = 0;
}
QueueArr::~QueueArr() {
delete[] values;
}
bool QueueArr::isEmpty() const {
if (counter)
return false;
else
return true;
}
bool QueueArr::isFull() const {
if (counter < maxSize)
return false;
else
return true;
}
bool QueueArr::enqueue(char x) {
if (isFull()) {
cout << "Error! The queue is
full." << endl;
return false;
}
else {
back = (back + 1) % maxSize;
values[back] = x;
counter++;
return true;
}
}
char QueueArr::dequeue() {
char x = -1;
if (isEmpty()) {
cout << "Error! The queue is
empty." << endl;
return -1;
}
else {
x = values[front];
front = (front + 1) %
maxSize;
counter--;
return x;
}
}
void QueueArr::displayQueue() const {
cout << "Front -->";
for (int i = 0; i < counter; i++) {
if (i == 0)
cout <<
"\t";
else
cout <<
"\t\t";
cout << values[(front + i) %
maxSize];
if (i != counter - 1)
cout <<
endl;
else
cout <<
"\t<--Back" << endl;
}
cout << endl;
}
In: Computer Science
C++ Question
Create two circular linked lists and find their maximum numbers. Merge the two circular linked lists such that the maximum number of 2nd circular linked list immediately follows the maximum number of the 1st circular linked list.
Input:
12 -> 28 -> 18 -> 25 -> 19-> NULL
5 -> 24 -> 12 -> 6 -> 15-> NULL
Output:
28 -> 24-> 25 -> 15 -> 19 -> 15->5-> 18 -> 25 -> 19->NULL
Note:- Code should work on MS-Visual studio 2017 and provide output along with code
In: Computer Science
Apply following to header and footer sections of page:
center text
background color rgb(254,198,179)
padding should be 20px
In: Computer Science
Describe/define/explain
a. The relationship between Java's Iterable and Iterator
interfaces
b. An inner class
c. An anonymous inner class
d. The functionality of an Iterator remove method
In: Computer Science
Assignment details
In: Computer Science
True False
The enqueue and dequeue operations in a priority queue take O(lg n) time, while linked list and array implementations take O(1) time. |
||
A binary heap is a (nearly) complete binary tree. |
||
Heaps usually use a linked node structure for implementation. |
||
When implementing heaps as arrays, you can leave a blank space at the front. If you do, the parent of a node at index i can be found at index floor(i/2). |
||
When implementing heaps as arrays, if you don't leave a space at the front, you can find the children of the node at index i at 2i and 2i+1. |
||
The heap order property states that each node must contain a value greater than its left child and less than its right child. |
||
Insertion in a heap is done by adding at the end of the array and "percolating up". |
||
The average case for insertion in a heap is O(lg n). The worst case is O(n). |
||
Deletion in a heap requires removing the root item and shifting all other items over one space. |
||
Building a heap by adding values one at a time is an O(n) operation. Building a heap "all at once" with the heapify() method (called buildHeap() in the textbook) is O(n lg n). |
In: Computer Science
I need to implement a code in python to guess a random number. The number must be an integer between 1 and 50 inclusive, using the module random function randint. The user will have four options to guess the number. For each one of the failed attempts, the program it should let the user know whether is with a lower or higher number and how many tries they have left. If the user guess the number, the program must congratulate the user and tell him how much he won. If you are a user, hit on the 1st attempt He wins first $ 100, on the second $ 75, on the third $ 50, on the fourth $ 25. If the user misses all four opportunities, the program must inform the user that he owes money $ 60 and what was the number that the computer generates randomly.
In: Computer Science
Explain the diagram of Computer System which includes (Hardware, OS, application program and users).
In: Computer Science