I am using C++
Start with the distance.cpp file on the website. Fill in the missing functions to enable the program to compile and correctly find determine which entered distance is larger. The user can either enter it in meters labeled with an “m”, or in feet and inches labeled with and ' and “. You may not change main(), we will check to ensure it is exactly the same. The meters and inches can be doubles, but the feet portion will always be in integers. Use the conversion that 1 foot = 0.305 meters. this is distance.cpp. I also CANNOT change anything about int main, i cant add anything to it or do anything to change it. I also need to use function overload.
#include <iostream>
using namespace std;
double strToDouble(string s);
int main()
{
Distance d1, d2;
cout << "Enter two distances: \n";
cin >> d1 >> d2;
if(d1 < d2)
{
cout << "First distance is smaller" << endl;
}
else if(d1 == d2)
{
cout << "Same distances" << endl;
}
else
{
cout << "First distance is larger" << endl;
}
}
double strToDouble(string s)
{
double expo = 1;
double current = 0;
bool before = true;
for(int i=0; i < s.length(); i++)
{
if(s[i] == '.')
{
before= false;
continue;
}
if(!before)
{
expo*=10;
}
current *= 10;
current += s[i]-'0';
}
return current/expo;
}



Copyable Code:
#include <iostream>
#include <string>
using namespace std;
double strToDouble(string s);
double convert(string s);
int main()
{
string a, b;
double d1, d2;
cout << "Enter two distances: \n";
cin >> a >> b;
if(a.find("'") <10)
d1 = convert(a);
else
d1 = strToDouble(a);
if(b.find("'") <10)
d2 = convert(b);
else
d2 = strToDouble(b);
if(d1 < d2)
{
cout << "First distance is smaller" << endl;
}
else if(d1 == d2)
{
cout << "Same distances" << endl;
}
else
{
cout << "First distance is larger" << endl;
}
}
double strToDouble(string s)
{
double expo = 1;
double current = 0;
bool before = true;
for(int i=0; i < s.length(); i++)
{
if(s[i] == '.')
{
before= false;
continue;
}
if(!before)
{
expo*=10;
}
current *= 10;
current += s[i]-'0';
}
return current/expo;
}
double convert(string s)
{
string temp;
temp = s.replace(s.find("'"), 1, "");
double d = strToDouble(temp);
return (d * 0.305);
}
I am using C++ Start with the distance.cpp file on the website. Fill in the missing...
////****what am i doing wrong? im trying to have this program with constructors convert inches to feet too I don't know what im doing wrong. (the program is suppose to take to sets of numbers feet and inches and compare them to see if they are equal , greater, less than, or not equal using operator overload #include <stdio.h> #include <string.h> #include <iostream> #include <iomanip> #include <cmath> using namespace std; //class declaration class FeetInches { private: int feet; ...
#include <iostream> #include <string> #include <stdio.h> using namespace std; /** The FeetInches class holds distances measured in feet and inches. */ class FeetInches { private: int feet; // The number of feet int inches; // The number of inches /** The simplify method adjusts the values in feet and inches to conform to a standard measurement. */ void simplify() { if (inches > 11) { feet = feet + (inches / 12); inches = inches % 12; } } /**...
c++, I am having trouble getting my program to compile, any help would be appreciated. #include <iostream> #include <string> #include <string.h> #include <fstream> #include <stdlib.h> using namespace std; struct record { char artist[50]; char title[50]; char year[50]; }; class CD { //private members declared private: string artist; //asks for string string title; // asks for string int yearReleased; //asks for integer //public members declared public: CD(); CD(string,string,int); void setArtist(string); void setTitle(string); void setYearReleased(int); string getArtist() const; string getTitle() const; int...
C++ I am using visual studio for it. Make a copy of the Rational class you created in the previous Lab. Modify the class. Replace all your mathematical, input, and output functions with overloaded operators. Overload the following 12 operators: + - * / < > = = ! = <= >= >> << In order to test your class in your main function, prompt the user for a numerator and a denominator for your first object. Repeat the prompt...
i am getting the warning warning: unknown escape sequence: '\s' and warning: unknown escape sequence: '\C' here is my code #include <iostream> #include <fstream> using namespace std; int main() { ifstream infile; infile.open("C:\\college\\C++\\scores.txt"); if(!infile) { cout<<"could not open"; return 0; else string p; string t; int s; string player[6]; string team[6]; int score[6]; while(infile>>p>>t>>s) { for(int i=0;i<6;i++) { p=player[i]; t=team[i]; s=score[i]; } } int scoreb=0,scorew=0; for(int i=0;i<6;i++) { if(team[i]=="Blue") scoreb=scoreb+score[i]; else if(team[i]=="White") scorew=scorew+score[i]; }...
Am I getting this error because i declared 'n' as an int, and then asking it to make it a double? This is the coude: #include "stdafx.h" #include <iostream> #include <fstream> #include <string> #include <algorithm> #include <vector> using namespace std; void sort(double grades[], int size); char calGrade(double); int main() { int n; double avg, sum = 0;; string in_file, out_file; cout << "Please enter the name of the input file: "; cin >> in_file; ...
I need to add something to this C++ program.Additionally I want it to remove 10 words from the printing list (Ancient,Europe,Asia,America,North,South,West ,East,Arctica,Greenland) #include <iostream> #include <map> #include <string> #include <cctype> #include <fstream> #include <iomanip> using namespace std; void addWord(map<std::string,int> &words,string s); void readFile(string infile,map<std::string,int> &words); void display(map<std::string,int> words); int main() { // Declaring variables std::map<std::string,int> words; //defines an input stream for the data file ifstream dataIn; string infile; cout<<"Please enter a File Name :"; cin>>infile; readFile(infile,words);...
I need to make a few changes to this C++ program,first of all it should read the file from the computer without asking the user for the name of it.The name of the file is MichaelJordan.dat, second of all it should print ,3 highest frequencies are: 3 words that occure the most.everything else is good. #include <iostream> #include <map> #include <string> #include <cctype> #include <fstream> #include <iomanip> using namespace std; void addWord(map<std::string,int> &words,string s); void readFile(string infile,map<std::string,int> &words); void display(map<std::string,int>...
I am having trouble understanding how this code is able to use the contents of the header file. Can someone please provide comments in the main code to describe what is happening? (especially on the bool isNumber) THE MAIN CODE: #include<bits/stdc++.h> #include "MyCartesianPoint.h" #include <math.h> #include <iostream> using namespace std; bool isNumber(string s) { if(!isdigit (s[0])) { if(s[0] != '-') return false; else if(s.length() == 1) return false;...
Can someone please edit my current code to accept a user input for the text file name in lieu of how it currently will read data1.txt. Also if the user enters a data file that isn't ready to be used, cout a statement "cout << "Could not open file " << userInputforData.txt << endl; Another condition that I need to add is if there is a special character anywhere in the word it cannot be an acceptable variable name. could...