Write a program that asks the user for a Fahrenheit temperature and calls a function name Celsius that returns the temperature in Celsius of the Fahrenheit temperature sent to it. Your function will look similar to this: double celsius(double f)
{
double c;
:
:
return c;
}
In: Computer Science
write a member function in C++ , that takes two lists and return list that contain the merge of the two lists
in the returned list: first insert the first list and then the
second list
In: Computer Science
Accounting Program in c++
Write a class to keep track of a balance in a bank account with a varying annual interest rate. The constructor will set both the balance and the interest rate to some initial values (with defaults of zero). The class should have member functions to change or retrieve the current balance or interest rate. There should also be functions to make a deposit (add to the balance) or withdrawal (subtract from the balance). You should not allow more money to be withdrawn than what is available in the account, nor should you allow for negative deposits. Finally, there should be a function that adds interest to the balance (interest accrual) at the current interest rate. This function should have a parameter indicating how many months’ worth of interest are to be added (for example, 6 indicate the account should have 6 months’ added). Interest is accrued from an annual rate. The month is representative of 1/12 that amount. Each month should be calculated and added to the total separately. For example: 1 month accrued at 5% APR is Balance = ((Balance * 0.05)/12) + Balance; For 3 months the calculations you repeat the statement above 3 times. Use the class as part of the interactive program provided below.
In: Computer Science
Using Java
Write the class RecursiveProbs, with the methods listed below. Write all the methods using recursion, NOT LOOPS. You may use JDK String Methods like substring() and length(), but do not use the JDK methods to avoid coding algorithms assigned. For example, don’t use String.revers().
public boolean recursiveContains(char c, String s) {
if (s.length() == 0)
return false;
if (s.charAt(s.length() - 1) == c)
return true;
else
return recursiveContains(c, s.substring(0, s.length() - 1));
}
public boolean recursiveAllCharactersSame(String s) return true if all the characters in the String are identical, otherwise false. if the String has length less than 2, all characters are identical.
public String recursiveHead(int n, String s) returns the substring of s beginning with the first character and ending with the character at n-1; in other words, it returns the first n characters of the String. Return empty String("") in cases in which n is zero or negative or exceeds the length of s.
Write either a main() or a JUnit test case for test
In: Computer Science
I'm getting a conversion issue with this program. When I ran this program using the Windows command prompt it compiles and runs without issues. Although, when I run it using the zyBooks compiler it keeps giving me these conversion errors in the following lines:
main.c: In function ‘main’:
main.c:53:24: error: conversion to ‘float’ from ‘long int’ may alter its value [-Werror=conversion] averageCpi += cpi[i] * instructionCount[i] * Million;
main.c:57:29: error: conversion to ‘float’ from ‘long int’ may alter its value [-Werror=conversion] averageCpi = averageCpi / (totalInstructions * Million);
main.c:58:47: error: conversion to ‘float’ from ‘long int’ may alter its value [-Werror=conversion] mips = (frequency * Million) / (averageCpi * Million);
main.c:58:37: error: conversion to ‘float’ from ‘long int’ may alter its value [-Werror=conversion] mips = (frequency * Million) / (averageCpi * Million);
main.c:59:32: error: conversion to ‘float’ from ‘long int’ may alter its value [-Werror=conversion] executionTime = ((averageCpi * (totalInstructions * Million)) / (frequency * Million)) * 1000;
main.c:59:65: error: conversion to ‘float’ from ‘long int’ may alter its value [-Werror=conversion] executionTime = ((averageCpi * (totalInstructions * Million)) / (frequency * Million)) * 1000;
cc1: all warnings being treated as errors
Is there a more efficient way to convert from float to long int?
Here is the program:
#include <stdio.h>
int main() {
int instructionCount[100], totalInstructions = 0, cpi[100], noOfClass = 0, frequency = 0, ch = 0;
float averageCpi = 0 , executionTime , mips;
const long MILLION = 1000000;
do{
printf("\n Performance Assessment: ");
printf("\n ----------- -----------");
printf("\n 1) Enter Parameters");
printf("\n 2) Print Results");
printf("\n 3) Quit");
printf("\n Enter Selection: ");
scanf("%d",&ch);
if(ch == 1){
printf("\n Enter the number of instruction classes: ");
scanf("%d",&noOfClass);
printf("\n Enter the frequency of the machine (MHz): ");
scanf("%d",&frequency);
for (int i = 0; i < noOfClass; ++i) {
printf("\n Enter CPI of class %d : ",(i+1));
scanf("%d", &cpi[i]);
printf("\n Enter instruction count of class %d (millions): ",(i+1));
scanf("%d", &instructionCount[i]);
totalInstructions += instructionCount[i];
}
} else if(ch == 2){
printf("\nFREQUENCY (MHz): %d", frequency);
printf("\nINSTRUCTION DISTRIBUTION");
printf("\nCLASS \t CPI \t COUNT");
for (int i = 0; i < noOfClass; ++i) {
printf("\n %d \t %d \t %d",(i+1), cpi[i], instructionCount[i]);
averageCpi += (cpi[i] * instructionCount[i] * MILLION);
}
averageCpi = averageCpi / (totalInstructions * MILLION);
mips = (frequency * MILLION) / (averageCpi * MILLION);
executionTime = ((averageCpi * (totalInstructions * MILLION)) / (frequency * MILLION)) * 1000;
printf("\n PERFORMANCE VALUES");
printf("\n AVERAGE CPI \t %.2f", averageCpi);
printf("\n TIME (ms) \t %.2f", executionTime );
printf("\n MIPS \t %.2f", mips);
printf("\n");
}
}while(ch != 3);
return 0;
}In: Computer Science
Answer each of the following. Assume that single-precision floating-point numbers are stored in 8 bytes, and that the starting address of the array is at location 2030100 in memory. Each part of the exercise should use the results of previous parts where appropriate.
a) Define an array of type float called numbers with 5 elements, and initialize the elements to the values 0.11, 0.22, 0.33, …, 0.55. Assume the symbolic constant SIZE has been defined as 5.
b) Define a pointer, nPtr, that points to an object of typefloat.
c) Print the elements of array numbers using array subscript notation. Use a for statement and assume the integer control variable i has been defined. Print each number with 2 position of precision to the right of the decimal point.
d) Give two separate statements that assign the address of last element of array numbers to the pointer variable nPtr.
e) Printthe elements of array numbers using pointer/offset notation with the pointer nPtr.
f) Print the elements of array numbers using pointer/offset notation with the array name as the pointer.
g) Print the elements of array numbers by subscripting pointer nPtr. h) Refer to element 2 of array numbers using array subscript notation, pointer/offset notation with the array name as the pointer, pointer subscript notation with nPtr and pointer/offset notation with nPtr. i) Assuming that nPtr pointsto the end of array numbers (i.e., the memory location after the last element of the array), what addressisreferenced by nPtr - 5? What value is stored at thatlocation? j) Assuming that nPtr points to numbers[5], what address is referenced by nPtr – = 2? What’s the value stored at that location?
In: Computer Science
def isPower(x, y):
"""
>>> isPower(4, 64)
3
>>> isPower(5, 81)
-1
>>> isPower(7, 16807)
5
"""
# --- YOU CODE STARTS HERE
def isPower(x, y):
num = x
count = 1
while x < y:
x *= num
count += 1
if x == y:
return count
return -1
def translate(translation, txt):
"""
>>> myDict = {'up': 'down', 'down': 'up', 'left': 'right', 'right': 'left', '1': 'one'}
>>> text = 'Up down left Right forward 1 time'
>>> translate(myDict, text)
'down up right left forward one time'
"""
# --- YOU CODE STARTS HERE
def translate(translationDict, txt):
words = txt.lower().split()
for i in range(len(words)):
if words[i] in translationDict:
words[i] = translationDict[words[i]]
return ' '.join(words)
def onlyTwo(x, y, z):
"""
>>> onlyTwo(1, 2, 3)
13
>>> onlyTwo(3, 3, 2)
18
>>> onlyTwo(5, 5, 5)
50
"""
# --- YOU CODE STARTS HERE
def onlyTwo(x, y, z):
m1 = max(x, y, z)
m2 = (x + y + z) - min(x, y, z) - m1
return m1 * m1 + m2 * m2
def largeFactor(num):
"""
>>> largeFactor(15)
5
>>> largeFactor(24)
12
>>> largeFactor(7)
1
"""
# --- YOU CODE STARTS HERE
def largeFactor(num):
n = num - 1
while n >= 1:
if num % n == 0:
return n
n -= 1
def hailstone(num):
"""
>>> hailstone(5)
[5, 16, 8, 4, 2, 1]
>>> hailstone(6)
[6, 3, 10, 5, 16, 8, 4, 2, 1]
"""
# --- YOU CODE STARTS HERE
def hailstone(num):
result = []
while num > 1:
result.append(num)
if num % 2 == 0:
num = num // 2
else:
num = 3 * num + 1
result.append(num)
return result
if any wrong with my code
In: Computer Science
What is the minimum length in hop by hop extension header in ipv6 ?
In: Computer Science
In this assignment, you are expected to rewrite the program from assignment7 using structs. That is, instead of using multiple arrays (one for each field, you need to create a single array of the datatype you should create as a struct).
So, write a C++ program (use struct and dynamic memory allocation) that reads N customer records from a text file (customers.txt) such as each record has 4 fields (pieces of information) as shown below:
Account Number (integer)
Customer full name (string)
Customer email (string)
Account Balance (double)
The program is expected to print the records in the format shown below, sorted in decreasing order based on the account balance:
Account Number : 1201077
Name : Jonathan I. Maletic
Email : [email protected]
Balance : 10,000.17
-------------------------------------
Note: The records stored in the following format (4 lines for each account). You need to create a text file that contains sample records as explained in class:
First Line is the account number
Second Line is full name
Third line is email
Forth line is the available balance
Important Note: You must create a struct called (Customer) with enough members (to hold record information) and use it to declare a dynamic array to store all the records (information) read from the file. Then sort the array and then print it. Use the example shared in class (see the slides) as a model for your program.
|
Example (data saved in text file) |
Output: |
|
1201077 Jonathan I. Maletic 10,000.17 1991999 John Smith 5,000.11 1333333 Bill Bultman 120,000.00 |
Account Number : 1333333 Name : Bill Bultman Email : [email protected] Balance : 120,000.00 ------------------------------------- Account Number : 1201077 Name : Jonathan I. Maletic Email : [email protected] Balance : 10,000.17 ------------------------------------- Account Number : 1991999 Name : John Smith Email : [email protected] Balance : 5,000.11 ------------------------------------- |
In: Computer Science
This is C++, please insert screenshot of output please.
Part1: Palindrome detector
Write a program that will test if some string is a palindrome
In: Computer Science
Problem 1 (Ransom Note Problem) in python
A kidnapper kidnaps you and writes a ransom note. He does not write it by hand to avoid having his hand writing being recognized, so he uses a magazine to create a ransom note. We need to find out, given the ransom string and magazine string, is it possible to create a given ransom note. The kidnapper can use individual characters of words.
Here is how your program should work to simulate the ransom problem:
Example: If the magazine string is “programming problems are weird”
If the ransom note is: “no see” your program should print true as all the characters in “no see” exist in the magazine string.
If the ransom note is “no show” your program should print false as not all the characters in “no show” exist in the magazine string as you can see the character ‘h’ does not exist.
In: Computer Science
1. What are some drawbacks to crowd sourced answers?
2. Do people generally utilize the diversity of sources on the Internet effectively?
3. How reliant are we and how reliant should we be on getting our news from social media?
In: Computer Science
Can anyone just check my code and tell me why the program doesn't show the end date & stops at the date before the end date? Tell me how i can fix it.
Question:
Write a program compare.cpp that asks the user to input two dates (the beginning and the end of the interval). The program should check each day in the interval and report which basin had higher elevation on that day by printing “East” or “West”, or print “Equal” if both basins are at the same level.
My code:
#include
#include
#include
#include
using namespace std;
int main()
{
string date;
string starting_date;
string ending_date;
double eastSt;
double eastEl;
double westSt;
double westEl;
int dateRange=0;
cout<< "Enter the starting date" << endl;
cin>> starting_date;
cout<< "Enter the ending date" << endl;
cin>> ending_date;
ifstream fin("Current_Reservoir_Levels.tsv");
if (fin.fail())
{
cerr << "File cannot be opened for reading." << endl;
exit(1);
}
string junk;
getline(fin, junk);
while(fin >> date >> eastSt >> eastEl >> westSt >> westEl)
{
fin.ignore(INT_MAX, '\n');
if (date == starting_date)
{
dateRange = 1;
}
if (date == ending_date)
{
dateRange= 0;
}
if (dateRange == 1)
{
if(eastEl > westEl)
{
cout<< date << " "<< "East " <
}
else if (eastEl < westEl)
{
cout<< date << " " << "West" <
}
else if (eastEl == westEl )
{
cout<< date << " " << "Equal" <
}
}
}
return 0;
}
Expected output
01/17/2018 West 01/18/2018 West 01/19/2018 West 01/20/2018 West 01/21/2018 West 01/22/2018 West 01/23/2018 West
Received output:
01/17/2018 West 01/18/2018 West 01/19/2018 West 01/20/2018 West 01/21/2018 West 01/22/2018 West
*************** F.H**************
In: Computer Science
Hello, I keep getting the error C4430: missing type specifier -
int assumed. Note: C++ does not support default-int for my code.
What am I doing wrong? I only have #include
<iostream>
int read_num(void);
main()
{
int num1, num2, max;
//find maximum of two 2 numbers
num1 = read_num();
num2 = read_num();
if (num1 > num2)
{
max = num1;
}
else
{
max = num2;
}
printf("the maximum number is: %d\n", max);
return;
}
int read_num(void)
{
int num;
printf("Enter a number: ");
scanf_s("%d", &num);
return (num);
}
In: Computer Science
1. Describe the basic components of network security and the differences between wired and wireless network security best practices.
In: Computer Science