1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
vichka [17]
3 years ago
9

Convert the following C program to C++.

Computers and Technology
1 answer:
ki77a [65]3 years ago
8 0

Answer:

The program equivalent in C++ is:

<em>#include <cstdio></em>

<em>#include <cstdlib></em>

#define SIZE 5

using namespace std;

<em>int main(int argc, char *argv[]) {</em>

<em>int numerator = 25;</em>

<em>int denominator = 10;</em>

<em>FILE * inPut = fopen(argv[1], "r");</em>

<em>FILE * outPut = fopen(argv[2], "w");</em>

<em>float result = (float)numerator/denominator;</em>

<em>fprintf(outPut,"Result is %.2f\n", result);</em>

<em>float arr[SIZE];</em>

<em>for(int i = 0; i < SIZE; i++) {</em>

<em>fscanf(inPut, "%f", &arr[i]);</em>

<em>fprintf(outPut, "%7.4f\n", arr[i]);</em>

<em>}</em>

<em>return 0;</em>

<em>}</em>

Explanation:

See attachment for explanation.

Each line were numbered with equivalent line number in the C program

Download cpp
You might be interested in
Write a program to read a sentence which is a single string. Then count the number of words in the sentence. The program will re
patriot [66]

Answer:

The program in Python is as follows:

sentence = input("Sentence: ")

words = len(sentence.split())

print("Words:", words)

Explanation:

This reads the sentence for the user

sentence = input("Sentence: ")

This counts the number of words

words = len(sentence.split())

This prints the number of words

print("Words:", words)

6 0
3 years ago
My friend Leo wants to have an emergency plan for his final exams on University of Southern Algorithmville. He has N subjects to
leonid [27]

Answer:

Greedy is an algorithmic paradigm that builds up a solution piece by piece, always choosing the next piece that offers the most obvious and immediate benefit. Greedy algorithms are used for optimization problems. An optimization problem can be solved using Greedy if the problem has the following property: At every step, we can make a choice that looks best at the moment, and we get the optimal solution of the complete problem.

If a Greedy Algorithm can solve a problem, then it generally becomes the best method to solve that problem as the Greedy algorithms are in general more efficient than other techniques like Dynamic Programming. But Greedy algorithms cannot always be applied. For example, the Fractional Knapsack problem (See this) can be solved using Greedy, but 0-1 Knapsack cannot be solved using Greedy.

The following are some standard algorithms that are Greedy algorithms.

1) Kruskal’s Minimum Spanning Tree (MST): In Kruskal’s algorithm, we create an MST by picking edges one by one. The Greedy Choice is to pick the smallest weight edge that doesn’t cause a cycle in the MST constructed so far.

2) Prim’s Minimum Spanning Tree: In Prim’s algorithm also, we create an MST by picking edges one by one. We maintain two sets: a set of the vertices already included in MST and the set of the vertices not yet included. The Greedy Choice is to pick the smallest weight edge that connects the two sets.

3) Dijkstra’s Shortest Path: Dijkstra’s algorithm is very similar to Prim’s algorithm. The shortest-path tree is built up, edge by edge. We maintain two sets: a set of the vertices already included in the tree and the set of the vertices not yet included. The Greedy Choice is to pick the edge that connects the two sets and is on the smallest weight path from source to the set that contains not yet included vertices.

4) Huffman Coding: Huffman Coding is a loss-less compression technique. It assigns variable-length bit codes to different characters. The Greedy Choice is to assign the least bit length code to the most frequent character. The greedy algorithms are sometimes also used to get an approximation for Hard optimization problems. For example, the Traveling Salesman Problem is an NP-Hard problem. A Greedy choice for this problem is to pick the nearest unvisited city from the current city at every step. These solutions don’t always produce the best optimal solution but can be used to get an approximately optimal solution.

6 0
3 years ago
In a paragraph, describe in detail a practical real-world example of where you would implement a singly-linked list and why a si
frosja888 [35]

Answer:

travel

Explanation:

One real world example of a singly-linked list would be travel. Imagine that you want to take a trip to your nearest neighbor state. To do so you would need to take a 2 buses and a train, but you can't just take any or in any order you wish. You first need to take the first bus at your current location, get off at the train station, take that train to the final stop, get off and take the bus to the final destination. Meaning there is a sequence of connected events that you must follow in order to get to your destination and the same opposite sequence of events to get back. This is exactly like a singly-linked list.

3 0
3 years ago
Can we opne a website form PowerPoint slide ​
Phoenix [80]

Answer:

Yes

Explanation:

Type in the link, play the presentation and click the link. Or hover over the link and press ctrl + click at the same time. (Don't know if I got the last part right)

3 0
4 years ago
Read 2 more answers
How important are operating system in our devices?​
TiliK225 [7]

Answer:

Explanation:

An operating system is the most important software that runs on a computer. ... It also allows you to communicate with the computer without knowing how to speak the computer's language. Without an operating system, a computer is useless.

6 0
2 years ago
Read 2 more answers
Other questions:
  • Someone help me I don’t know what to do /COMPUTER SCIENCE
    5·1 answer
  • The reason why a database table is in the first normal form (1NF), but not in the second form (2NF) is because:
    12·1 answer
  • Stella is a bank executive. She is preparing a spreadsheet on the loan repayment schedules of customers. Which function can she
    9·1 answer
  • What hex value is the standard indicator for jpeg graphics files?​?
    6·1 answer
  • An employee who interacts with customers regarding the nature of their car problems, rather than actually working on the vehicle
    6·1 answer
  • Which CSS attribute would change an element's font color to blue
    15·2 answers
  • Study the sentences below. A.Changing the properties of characters in a sentence or paragraph in a Word document helps increase
    5·2 answers
  • Write any three type of looping structure with syntax​
    13·1 answer
  • def list_length(shrinking_list): ''' A recursive way to count the number of items in a list. ''' if shrinking_list
    10·1 answer
  • _______ are useful when you want the user to select one choice from several possible choices. Radio buttons Check boxes Buttons
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!