(C++)Heapsort: Write C++ codes for heapsort. The input array is a random permutation of A={1,
2, 3, …, 99, 100}. You should write codes to generate and print the random permutation first.
In: Computer Science
Python3 Please add comments
Write a program that implements the word guessing game
- There is a secret word
- The user enters letters one at a time, if the letter appears in the secret word, it is revealed. Otherwise, it counts as a wrong guess.
If the user reveals all the letters in the word before getting too many wrong guesses then they win!
Otherwise, they lose.
1 - define secret word
2 - create a revealed letter list that starts empty
2. set wrong guess count to 0
3. ask the user for a letter
4. is the letter in the secret word?
5. if so: add it to the revealed letters list
create a blank string
for each letter in the secret word, if the letter in
revealed letter list, add that letter to string,
otherwise add an underscore to string
6. if letter not in secret word, add one to wrong guess
7. repeat from step 3
In: Computer Science
Hello, I need to convert this java array into an array list as I am having trouble please.
import java.util.Random; import java.util.Scanner; public class TestCode { public static void main(String[] args) { String choice = "Yes"; Random random = new Random(); Scanner scanner = new Scanner(System.in); int[] data = new int[1000]; int count = 0; while (!choice.equals("No")) { int randomInt = 2 * (random.nextInt(5) + 1); System.out.println(randomInt); data[count++] = randomInt; System.out.print("Want another random number (Yes / No)? "); choice = scanner.next(); } int min = data[0], max = data[0]; for (int i = 0; i < count; i++) { if (data[i] > max) max = data[i]; if (data[i] < min) min = data[i]; } System.out.println("Percentage of Yes values is " + (((count-1)*100.0)/count)); System.out.println("Maximum value is " + max); System.out.println("Minimum value is " + min); } }
In: Computer Science
C
Implement the function Append (char** s1, char** s2) that appends the second character array to the first, replaces the first array with the result and replaces the second character array with the original first array. For example, if the first character array is "hello" and the second is "world" at the end of the function the new value of the first character array should be"helloworld" and the second array should be "hello". If the input is invalid the function should return 1. Otherwise, the function should return 0.
Input is double pointer (**). No use of <string.h>, USE malloc
#include <stdlib.h>
#include <stdio.h>
int
Append(char **s1, char **s2){
//implement
}
int main(){
char myArray1[7] = "hello";
char myArray2[10] = "world";
char *myArray3 = myArray1;
char *myArray4 = myArray2;
Append(&myArray3, &myArray4);
return 0;
}
In: Computer Science
C++ needed
Create a loop which gives the player instructions on what to input. Then read input from the player. The input will be either one of three options:
• If the user enters the word “answer” or some other string you choose to indicate the player is ready to end the game and guess. In this case, output the hidden rule.
• Three numbers separated by spaces. Let’s call a trio of numbers and the corresponding output a Guess. Once a user makes a Guess. If the user enters a sequence that follows the rules, output “Yes!” Otherwise output “No.”
• Treat any other entry as an exception.
In: Computer Science
Design the logic in pseudocode for Bugz App software company
that sells a software package
as follows.
1. The retail price of the package is $99
2. Quantity discounts are given on purchases of 10 or more units as
follows The program
must allow the user to enter the customer’s name and number of
units purchased, and
output the original cost of the units purchased, the percentage
discount given, the dollar
amount of the discount given, and the final cost after
discount.
1. If the customer purchases up to 19 units, they receive a
discount of 20%
2. 20 to 49 units – discount of 30%
3. 50 to 99 units – discount of 40%
4. 100 or more units – discount of 50%
In: Computer Science
C++ please
Instructions
Download and modify the Lab5.cpp program.
Currently the program will read the contents of a file and display each line in the file to the screen. It will also display the line number followed by a colon. You will need to change the program so that it only display 24 lines from the file and waits for the user to press the enter key to continue.
Do not use the system(“pause”) statement.
Download Source Lab 5 File:
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
using namespace std;
int main()
{
ifstream file; // File stream object
string name; // To hold the file name
string inputLine; // To hold a line of input
int lines = 0; // Line counter
int lineNum = 1; // Line number to display
// Get the file name.
cout << "Enter the file name: ";
getline(cin, name);
// Open the file.
file.open(name);
// Test for errors.
if (!file)
{
// There was an error so display an error
// message and end the program.
cout << "Error opening " << name << endl;
}
else
{
// Read the contents of the file and display
// each line with a line number.
while (!file.eof())
{
// Get a line from the file.
getline(file, inputLine, '\n');
// Display the line.
cout << setw(3) << right << lineNum
<< ":" << inputLine << endl;
// Update the line display counter for the
// next line.
lineNum++;
// Update the total line counter.
lines++;
}
// Close the file.
file.close();
}
return 0;
}
In: Computer Science
HTML 5
(Website Registration Form with Optional Survey) Create a website registration form to obtain a user’s first name, last name and e-mail address. In addition, include an optional survey question that asks the user’s year in college (e.g., Freshman). Place the optional survey question in a details element that the user can expand to see the question.
In: Computer Science
Describe some design trade-offs between efficiency and safety in some language you know.
In: Computer Science
Write a Java program that uses printf, and takes user input to find the name of the File.
Write a program that compares to files line by line, and counts the number of lines that are different. You can use file1.txt and file2.txt when testing your program, but you must ask for the file names in the input.
main
Interactively requests the names of the two files, after creating the Scanner for the keyboard.
Creates a Scanner for each of the two files.
Calls countDifferentLines with references to the two Scanners as parameters and accepts an integer return value.
Prints the result (see sample).
countDifferentLines
Accepts references to the two Scanners as parameters
Compares the two files line by line – They may have a different number of lines
Return the number of lines that are different
Sample output
Please enter name of the first file to compare: file1.txt
Please enter name of the second file to compare: file2.txt
The files differ in 4 line(s)
In: Computer Science
HTML 5
(Creating an Autocomplete Form with a datalist) Create an autocomplete input element with an associated datalist that contains the days of the week.
In: Computer Science
In: Computer Science
in MIPS assembly, ask a user for two numbers and to either enter a '1' for addition or '2' for subtraction. using jal, jump to the appropriate procedure for additing or subtracting. then print out result and ask if there is another calculation (terminate program if 'no').
In: Computer Science
In coding language C, Write a program in which will use floating point variable (input=232.346) and print out: 1. scientific notation form of input. 2. floating point form of input with total width 12 (default right aligned). 3. floating point form of input with total width 12 (default right aligned) and add 0s for unused space. 4. floating point form of input with total width 12 (left aligned). 5. floating point form of input with total width 12 (default right aligned) and limit number of digits after decimal point to 2 i.e. (precision of 2 digits)
In: Computer Science
C++
Here is a program that to validate the ISBN number from user typed and output "Valid" if the number is valid, and "Invalid" otherwise.
I want to change this program to read the file, and to validate the ISBN number from the file.
Please add comments.
#include <iostream>
#include <string>
using std::cin;
using std::cout;
using std::string;
// remove dashes convert letters to upper case
string normalize(const string &isbn) {
string ch;
for (char i : isbn) {
if (i == '-') {
continue; // if "-" then skip it
}
if (isalpha(i)) {
i = toupper(i); // Check uppercase
}
ch += i;
}
return ch;
}
// return the number of digits in to the string
size_t numDigits(string &str) {
size_t numDigits = 0;
for (char ch : str) {
if (isdigit(ch)) {
++numDigits;
}
}
return numDigits;
}
enum ValidationCode {
Ok, // validation passed
NumDigits, // wrong number of digits
ExtraChars // extra characters in isbn
};
enum ValidationCode validate(string &isbn) {
string normal = normalize(isbn);
size_t count = numDigits(normal);
if (count != 10) {
return NumDigits;
}
if (normal.size() == 10 || normal.size() == 11 && normal[10] == 'X') {
return Ok;
}
return ExtraChars;
}
int main() {
string str;
while (cin >> str) {
switch (validate(str)) {
case Ok:
cout << str << " is a valid isbn\n";
break;
case NumDigits:
cout << str << " doesn't have 10 digits\n";
break;
case ExtraChars:
cout << str << " has extra characters\n";
break;
default:
cout << "ERROR: validate(" << str << ") return an unknown status\n";
break;
}
}
}
isbn_data.text
1-214-02031-3
0-070-21604-5
2-14-241242-4
2-120-12311-x
0-534-95207-x
2-034-00312-2
1-013-10201-2
2-142-1223
3-001-0000a-4
done
In: Computer Science