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
In: Computer Science
This code needs to run a working Reverse Polish Calculator, but when I input my commands it only pops my inputs never push them. So my answer is always zero.
Here is my code.
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
struct Node
{
int element;
struct Node *next;
};
//Global variable
struct Node *top = NULL;
void push(int ele)
{
struct Node *newNode;
newNode = (struct Node *) malloc(sizeof(struct Node));
newNode->element = ele;
newNode->next = top;
top = newNode;
}
void pop()
{
struct Node *temp;
temp = top;
if(top == NULL)
printf("Stack is empty!!!\n");
else
{
top = top->next;
printf("%d is popped from the stack\n", temp->element);
free(temp);
}
}
bool isEmpty()
{
if(top == NULL)
return true;
else
return false;
}
int returnTopElement()
{
return top->element;
}
void printStack()
{
struct Node *temp;
temp = top;
printf("Stack : ");
while(temp != NULL)
{
printf("%d ", temp->element);
temp = temp->next;
}
printf("\n");
}
int oneByOne(){
char test; //taking character input
int num = 0;
int num1;
int num2;
int atleastone = 0;
printf("Enter your inputs separated by a space and the
operation.\n");
printf("Enter ! when you are done.\n");
while(1){
scanf("%c",&test); //take input of current character
printf("%c is user character\n", test);
if(test == '!'){break;} //terminates character
if(test == ' ' || test == '\n'){ //allows for space or newline
input
if(atleastone) //check if at least one previous digit scanned
push(num);
num = 0, atleastone = 0;
continue;
}
else if(test>='0' && test <='9'){
atleastone = 1;
num = num*10 + (test - '0');
continue;
}
if(top == NULL){
printf("This operation is invalid.\n");
break;
}
num1 = returnTopElement(); pop();
if(top == NULL){
printf("This operation is invalid.\n");
break;
}
num2 = returnTopElement(); pop();
if(test == '+');
push(num2+num1); //allows addition
if(test == '-');
push(num2-num1); //allows subtraction
if(test == '*');
push(num2*num1); //allows multiplication
if(test == '/');
push(num2/num1); //allows division
}
if(top == NULL)
return -1;
return returnTopElement();
}
int arrayInput(char** inputArray){
int i = 0;
int atleastone = 0;
int num = 0;
int num1;
int num2;
char test;
while((*inputArray)[i] != '\0'){
test = (*inputArray)[i];i++; //gets char input from function
if(test == '!'){break;} //terminate character
if(test == ' ' || test == '\n'){ //allows for space or newline
input
if(atleastone)
push(num);
num = 0, atleastone = 0;
continue;
}
else if(test >= '0' && test <= '9'){
atleastone = 1;
num = num*10 + (test- '0');
continue;
}
if(top == NULL){
printf("This operation is invalid.\n");
break;
}
num2 = returnTopElement(); pop();
if(test == '+');
push(num2+num1); //allows addition
if(test == '-');
push(num2-num1); //allows subtraction
if(test == '*');
push(num2*num1); //allows multiplication
if(test == '/');
push(num2/num1); //allows division
}
if(top == NULL)
return -1;
return returnTopElement();
}
int main(int argc, const char * argv[]) {
printf("Check oneByone function: \n");
int ans = oneByOne();
if(top == NULL){
printf("The input is invalid.\n");
}
else{
printf("The answer is %d\n", ans);
}
char * e = "23 45 + 3 *";
char ** expression = &e;
printf("\nChecking arrayInput function for %s \n",
*expression);
printf("The above expression is hardcoded in the code itself.
\n");
ans = arrayInput(expression);
if(top == NULL){
printf("The input expression is invalid. \n");
}
else{
printf("The answer of the input expression is %d\n", ans);
}
return 0;
}
In: Computer Science
Explain the importance of awareness when dealing with employees security. Provide an example of two security policies that would help prevent internal employee fraud.
In: Computer Science