shape.h
#pragma once
#include <iostream>
#include <string>
#include <cmath>
#include <climits>
#include <sstream>
#include <fstream>
#include <deque>
using namespace std;
class Shape {
public:
Shape(string colorc);
virtual ~Shape();
string getColor(string getcolor);
virtual void print() = 0;
private:
string color;
};
shape.cpp
#include "Shape.h"
using namespace std;
Shape::Shape(string colorc) {
color = colorc;
}
string Shape::getColor(string getcolor) {
color = getcolor;
return color;
}
this code does not compile because of
Shape::Shape(string colorc) {
color = colorc;
}
i dont get why this is not compiling ive defined parameter on header file 'string colorc' and i am just calling the constructor when i write /**\ the code compiles
/*Shape::Shape(string colorc) {
color = colorc;
}*/
help please thank you
In case of any query do comment. Please rate answer as well. Thanks
Answer:
Usually this error comes when you declare a virtual method but did not define . I have seen that in Shape class you defined Destructor as Virtual so you have to provide definition to it in Shape.h itself. There are two ways to solve it:
1) in Shape.h, provide definition of it as below:
virtual ~Shape() = 0;
After that code compiles.

2) Provide the definition in Shape.cpp as below:
Shape::~Shape(){
color =""; //anything will work for compilation
}

shape.h #pragma once #include <iostream> #include <string> #include <cmath> #include <climits> #include <sstream> #include <fstream> #include...
Please add a detailed comment for this program. #include<iostream> #include<string> #include<fstream> #include<sstream> #include<cctype> using namespace std; int is_palindrome(string word){ int len = word.size(); for(int i=0; i<len/2; i++){ if(toupper(word[i])!=toupper(word[len-i-1])) return 0; } return 1; } int have_vowels3(string word){ int cnt = 0; for(int i=0; i<word.size(); i++){ if(tolower(word[i])=='a' || tolower(word[i])=='e' || tolower(word[i])=='i' || tolower(word[i]) =='o' || tolower(word[i]) == 'u') cnt++; } if(cnt>=3) return 1; else return 0; } int have_consecutives(string word){ for(int i=0; i<word.size()-1; i++){ if(tolower(word[i])=='o' && tolower(word[i+1]=='o')) return 1; } return...
#include <iostream> #include <string> #include <fstream> #include <sstream> using namespace std; struct transition{ // transition structure char start_state, to_state; char symbol_read; }; void read_DFA(struct transition *t, char *f, int &final_states, int &transitions){ int i, j, count = 0; ifstream dfa_file; string line; stringstream ss; dfa_file.open("dfa.txt"); getline(dfa_file, line); // reading final states for(i = 0; i < line.length(); i++){ if(line[i] >= '0' && line[i] <= '9') f[count++] = line[i]; } final_states = count; // total number of final states // reading...
*HOW DO I CHANGE THIS FROM A VOID FUNCTION TO A NON-VOID WITH PARAMETERS?* #include<iostream> #include<fstream> #include<string> using namespace std; void studentStats() { ifstream inputFile; inputFile.open("outFile.txt"); string studentData; string studentID; string ID, exam1, exam2, exam3; string header; cout << "Enter a Student ID: "; cin >> studentID; bool found =false; while (inputFile) { inputFile >> ID; inputFile >> exam1; inputFile >> exam2; inputFile >> exam3; if (ID.compare(studentID)==0) { cout << ID << " " << exam1 << " " <<...
#include <iostream> #include <iomanip> #include <cstdlib> #include <fstream> #include <string> #include <vector> #include <sstream> using namespace std; void DisplayMenu() { cout << "1. E games\n"; cout << "2. T games\n"; cout << "3. M games\n"; cout << "4. Total Games\n"; cout << "5. Exit\n"; } double total(double egames, double tgames, double mgames) { int totalgames = egames + tgames + mgames; cout << "There are " << totalgames << " games\n"; return...
#include <iostream> #include <vector> #include <fstream> #include <time.h> #include <chrono> #include <sstream> #include <algorithm> class Clock { private: std::chrono::high_resolution_clock::time_point start; public: void Reset() { start = std::chrono::high_resolution_clock::now(); } double CurrentTime() { auto end = std::chrono::high_resolution_clock::now(); double elapsed_us = std::chrono::duration std::micro>(end - start).count(); return elapsed_us; } }; class books{ private: std::string type; int ISBN; public: void setIsbn(int x) { ISBN = x; } void setType(std::string y) { type = y; } int putIsbn() { return ISBN; } std::string putType() { return...
//Vehicle.h
#pragma once
#include<iostream>
#include"Warranty.h"
#include<string>
using namespace std;
class Vehicle{
protected:
string make;
int year;
double mpg;
Warranty warranty;
static int numOfVehicles;
public:
Vehicle();
Vehicle(string s, int y, double m, Warranty
warranty);
Vehicle(Vehicle& v);
~Vehicle();
string getMake();
int getYear();
double getGasMileage();
void setMake(string s);
void setYear(int y);
void setYear(string y);
void setGasMileage(double m);
void setGasMileage(string m);
void displayVehicle();
static int getNumVehicles();
Warranty getWarranty();
void setWarranty(Warranty& );
};
//Vehicle.cpp
#include "Vehicle.h"
#include <string>
Vehicle::Vehicle()
{
make = "unknown";
year =...
I need a really good Pseudo/Algorithm code for this C++ program below. #include <iostream> #include<fstream> using namespace std; int main() { int low, high, i;//integer varaible bool flag;//boolean flag string a = "Enter two numbers(intervals): ";//string datatype ofstream f;//fow writing to file f.open("a.txt"); cout << a; cin >> low >> high; cout << "Prime numbers between " << low << " and " << high << " are: "; do /*...
So my test.h file has: #include <iostream> #include <fstream> using namespace std; class test { private: int data[]; public: test(string filename); }; My test.cpp file has: #include "sort.h" test::test(string filename) { ifstream inFile; inFile.open(filename); int iter = 0; while(!inFile.eof()) { cin >> data[iter]; iter++; } int numberOfNumbers = iter; for (iter = 0; iter < numberOfNumbers; iter++) cout << data[iter] << " "; ...
C++ Standard Deviation with arrays and vectors: #include <vector> #include <cmath> #include <iostream> using namespace std; void fillVector(vector <double> &); double average(const vector <double> &); int main() { return 0; } void fillVector(vector <double> &v) { double d; while (cin >> d) { v.push_back(d); } } double average(const vector <double> &v) { double sum = 0.; for (int i = 0; i < v.size(); i++) { sum += v.at(i); } return sum / v.size(); } standardDeviation() //stuck on this part...
CONVERT THE FOLLOWING C/C++ PROGRAM INTO JAVA: //LinkedString.h #pragma once #include<iostream> #include<string> using namespace std; //declare a node datastruct struct Node { char c; Node *next; }; class LinkedString { Node *head; public: LinkedString(); LinkedString(char[]); LinkedString(string); char charAt(int) const; string concat(const LinkedString &obj) const; bool isEmpty() const; int length() const; LinkedString substring(int, int) const; //added helper function to add to linekd list private: void add(char c); };...