Question: Hello, I wrote a code with the following guidelines, at the very bottom is my code and what went wrong, i got a 80/100 could
Hello, I wrote a code with the following guidelines, at the very bottom is my code and what went wrong, i got a 80/100 could someone please fix it.
Hello, below is a Lab we are doing
Lab 7
For this second lab on functions we once again work on writing a series of functions that can then be used by a larger function. In this case we are going to be write several conversion functions for converting between several different kinds of measures. Then we will write a controller function that will allow us to script the use of our converter functions.
Details
For this lab, you will write 8 functions that will need to follow the signatures that are given below. I will be testing your code by both calling these functions directly and using the main conversions function that will allow us to script the other functions.
void fromSeconds( int time, int& minutes, int& seconds); int toSeconds( int hours, int minutes, int seconds ); double toCelsius( double degrees ); double toFahrenheit( double degress ); double toInches( double centimeters ); double toCentimeters( double inches ); double toMiles( double kilometers ); double toKilometers( double miles );
These are the 8 conversion functions. They must be written as shown, i.e. I will be calling these function explicitly and if you dont follow their signatures, your code will not compile and youll get a bad grade.
Additionally, youll need to write the function below, that will allow for scripting of those functions.
void conversions( string input, string output );
I encourage, but am not requiring, the use of the following constants to help in the conversions.
const double CTOF = 5.0/9.0; const double FTOC = 9.0/5.0; const double CTOI = 2.54; const double KTOM = 1.609344;
Ill be explaining each of the 8 functions that are shown above here:
fromSeconds - this function takes as input an integer that represents a time in seconds, you are to take that given time and compute the number of minutes and seconds. You will use the pass-by-reference parameters, minutes and seconds to give back the two answers.
toSeconds - this will take the 3 parameters, hours, minutes, and seconds, and return the total time in seconds.
toCelsius - this will take the given temperature in Celsius, and return the corresponding temperature in Fahrenheit.
toFahrenheit - this will take the given temperature in Fahrenheit, and return the corresponding temperature in Celsius.
toInches - this will take the given measurement, in centimeters, and return the corresponding measurement in inches.
toCentimeters - this will take the given measurement, in inches, and return the corresponding measurement in centimeters
toMiles - this will take the given distance, in kilometers, and return the corresponding distance in miles.
toKilomoeters - this will take the given distance, in miles, and return the corresponding distance in kilometers.
The constants Im encouraging you to use are used in the conversions and are the constant factors you need.
The final function is the main function that will allow for an input file to control which functions are used. It will understand the following set of commands:
to-seconds 4:50:06
from-seconds 654
to-Celsius 68.4
to-Fahrenheit 23.4
to-inches 23.1
to-centimeters 45.2
to-miles 5
to-kilometers 3.1
Each of the commands will be followed by an argument. The ones that are above are example arguments. They show the format of the argument for the command. For example, to-seconds will be followed by a time in hour:minute:second form and the hours and minutes and minutes and seconds will be separated with a colon (:). The rest of the arguments are simply double numbers.
Input
to-seconds 4:50:06 from-seconds 654 to-Celsius 68.4 to-Fahrenheit 23.4 to-inches 23.1 to-centimeters 45.2 to-miles 5 to-kilometers 3.1
The input is simply the command followed by the argument. If this is the input, then the output will be shown below.
Output
Heres the corresponding output for the given input:
Command: to-seconds 4 50 6 17406 Command: from-seconds 654 10:54 Command: to-Celsius 68.4 20.2222 Command: to-Fahrenheit 23.4 74.12 Command: to-inches 23.1 9.09449 Command: to-centimeters 45.2 114.808 Command: to-miles 5 3.10686 Command: to-kilometers 3.1 4.98897
Each line of output will start with the word Command: followed by the command, the argument and then the result of the command. In the case of the fromSeconds, the output is shown as minutes:seconds. The precision of the decimals is the default precision. Do not use setprecision to adjust them.
Requirements
Heres a list of requirements
All of the functions shown above must be declared in a file name: lab7.h
You must implement the functions in a cpp file. Do not implement the code in the header.
============================================
My Code
=============
Lab7.cpp
#include
#include
#include
#include
#include "lab7.h"
using namespace std;
int compare(string one, string two) {
int i = 0;
while (one[i] != '\0') {
if (two[i] != '\0' && one[i] != two[i]) {
break;
}
i++;
}
if (one[i] == '\0')
return 0;
else
return 1;
}
int main() {
string input ="COMMAND TO GET IN THIS STRING", temp = "GET NUM IN THIS STRING";
fstream file;
file.open("C:\\Users\\ROHIT\\Documents\\visual studio 2013\\Projects\\Practice\\Debug\\input.txt");
string line;
int i, j, hrs, min, sec;
double result;
getline(file, line);
while (line.length() > 0) {
i = 0;
j = 0;
//extract command
while (line[i] != ' ') {
input[j] = line[i];
j++;
i++;
}
input[j] = '\0';
if (compare("to-seconds", input) == 0) {
j = 0;
i++;
while (line[i] != ':'){
temp[j] = line[i];
j++;
i++;
}
temp[j] = '\0';
hrs = stoi(temp);
j = 0;
i++;
while (line[i] != ':'){
temp[j] = line[i];
j++;
i++;
}
temp[j] = '\0';
min = stoi(temp);
j = 0;
i++;
while (line[i] != '\0'){
temp[j] = line[i];
j++;
i++;
}
temp[j] = '\0';
sec = stoi(temp);
cout
}
else if (compare("from-seconds", input) == 0) {
j = 0;
i++;
while (line[i] != '\0'){
temp[j] = line[i];
j++;
i++;
}
temp[j] = '\0';
int time;
time = stoi(temp);
fromSeconds(time, min, sec);
cout
}
else if (compare("to-Celsius", input) == 0) {
j = 0;
i++;
while (line[i] != '\0'){
temp[j] = line[i];
j++;
i++;
}
temp[j] = '\0';
double far;
far = stod(temp);
cout
}
else if (compare("to-Fahrenheit", input) == 0) {
j = 0;
i++;
while (line[i] != '\0'){
temp[j] = line[i];
j++;
i++;
}
temp[j] = '\0';
double far;
far = stod(temp);
cout
}
else if (compare("to-inches", input) == 0) {
j = 0;
i++;
while (line[i] != '\0'){
temp[j] = line[i];
j++;
i++;
}
temp[j] = '\0';
double far;
far = stod(temp);
cout
}
else if (compare("to-centimeters", input) == 0) {
j = 0;
i++;
while (line[i] != '\0'){
temp[j] = line[i];
j++;
i++;
}
temp[j] = '\0';
double far;
far = stod(temp);
cout
}
else if (compare("to-miles", input) == 0) {
j = 0;
i++;
while (line[i] != '\0'){
temp[j] = line[i];
j++;
i++;
}
temp[j] = '\0';
double far;
far = stod(temp);
cout
}
else if (compare("to-kilometers", input) == 0) {
j = 0;
i++;
while (line[i] != '\0'){
temp[j] = line[i];
j++;
i++;
}
temp[j] = '\0';
double far;
far = stod(temp);
cout
}
//clear line for next read
line = "\0";
getline(file, line);
}
return 0;
}
/* lab7.cpp */
#include "lab7.h"
#include
#include
void fromSeconds(int time, int& minutes, int& seconds) {
minutes = time / 60;
seconds = time % 60;
}
int toSeconds(int hours, int minutes, int seconds) {
return hours * 60 * 60 + minutes * 60 + seconds;
}
double toCelsius(double degrees) {
const double CTOF = 5.0 / 9.0;
return (degrees - 32) * CTOF;
}
double toFahrenheit(double degress) {
const double FTOC = 9.0 / 5.0;
return degress*FTOC + 32;
}
double toInches(double centimeters) {
const double CTOI = 2.54;
return centimeters / CTOI;
}
double toCentimeters(double inches) {
const double CTOI = 2.54;
return inches * CTOI;
}
double toMiles(double kilometers) {
const double KTOM = 1.609344;
return kilometers / KTOM;
}
double toKilometers(double miles) {
const double KTOM = 1.609344;
return miles*KTOM;
}
void conversions(std::string input, std::string output) {
std::cout
}
===============
Lab7.h
==============
#include
void fromSeconds(int time, int& minutes, int& seconds);
int toSeconds(int hours, int minutes, int seconds);
double toCelsius(double degrees);
double toFahrenheit(double degress);
double toInches(double centimeters);
double toCentimeters(double inches);
double toMiles(double kilometers);
double toKilometers(double miles);
void conversions(std::string input, std::string output);
==============
Attached is pictures of what his I/O were vs mine also hints below:
His:

Mine:

Edave_tesf09_output.fxi 1 Command: to-inches 16.8 6.61417 2 Command: to-kilometers 90.23 145.211 3 Command: to-seconds 38 69 21 140961 4 Command: to-miles 11.44 7.10849 5 Command: to-inches 82.56 32.5039 6 Command: to-seconds 52 4 2 187442 7 Command: from-seconds 857 14:17 davetest10output.txt - - - 1 Command: to-inches 53.49 21.0591 2 Command: from-seconds 597 9:57 3 Command: to-Celsius 58.5 14.7222 4 Command: to-kilometers 61.44 98.8781 5 Command: to-miles 78.16 48.5664 6 Command: to-centimeters 68.58 174.193 7 Command: to-inches 86.51 34.0591 8 Command: to-Celsius 32.21 0.116667 9 Command: to-kilometers 51.81 83.3801
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
