C++ :: Errors While Writing Car Class Program

Oct 9, 2013

Ive been writing this code all day and these errors have been killing.

Instructions:
Car Class:
Write a class named Car that has the following:
year. An int that holds the cars model year.
make. A string object that holds the make of car.
speed. An int that holds the cars current speed.

In addition, the class should have the following member functions.

Constructor. The constructor should accept the car's year and make as arguments and assign these values to a object's year and make member variables. The constructor should initialize the speed member variable to 0.

Accessors. Appropriate accessor functions should be created to allow values to be retrieved from an object's year, make, and speed member variables.

accelerate. the accelerate function should add 5 to the speed member variable each time it is called.

brake. The brake function should subtract 5 from the speed member variable each time it is called.

Demonstrate the class in a program that creates a Car object, and then calls accelerate function five times. After each call to the accelerate function, get the current speed of the car and display it. The, call the brake function five times. After each call to the brake function, get the current speed of the car and display it.

Errors: error C2061: syntax error : identifier 'stringm'
error C2533: 'Car::{ctor}' : constructors not allowed a return type
error C2511: 'Car::Car(int)' : overloaded member function not found in 'Car'
see declaration of 'Car'
fatal error C1903: unable to recover from previous error(s); stopping compilation

#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;

[Code].....

View 2 Replies


ADVERTISEMENT

C/C++ :: Repeating Errors On Overloading Non Member Class Program

Oct 21, 2014

I am having a issues with an assignment in my class and don't really understand why. I am getting undeclared identifier errors even though I have declared and I am also getting an error. Here is the code:

#include "stdafx.h"
#include <iostream>
#include <cassert>

[Code].....

Last time I came to you all with an error it was a simple brain fart on my part but I don't think this one is like that. I would love to tell you what the program is supposed to do but I still do not really know, which might be part of the problem. I guess it outputs different sized rectangles...

View 7 Replies View Related

C/C++ :: Writing Program For Class Where User Enters Their Age?

Aug 18, 2014

I am writing a program for a class where the user enters their age, how much money they have, and their full name. I know that I have to use the getline method to get the user's full name, and I know that I have to use cin.ignore() before that code, but i'm not sure why I have to use cin.ignore()?

View 1 Replies View Related

C++ :: Class Course / Constructor Errors

Mar 22, 2014

# include <iostream>
# include <cstring>
#include <iomanip>
#include <cmath>
using namespace std;
class Course
// Creating the class Course

[Code] ....

Errors: Warning1warning C4996: 'strncpy': This function or variable may be unsafe. Consider using strncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS.

[Code] .....

I have to create an Array of type Course and then fill its member dats using various member functions. Those errors are caused by some Constructor defect, which I dont really know what it is.

View 2 Replies View Related

C++ :: Class To Manage Pointers Better - Some Errors

Nov 19, 2013

I wrote a class to manage pointers better (because I am making a large program and don't want to call a constructor on somthing that was already deleted... etc...), but I am getting some compiler errors. I'm not sure what to do.

here is the class prototype:

template<typename type>
class pointer_class{
public:
pointer_class() : dat(NULL), del(false) {}
explicit pointer_class(const pointer_class<type>& d) : dat(NULL),

[Code].....

View 19 Replies View Related

C++ :: Finding Errors In Class Template

Nov 17, 2014

I have to find at least 5 errors in the following class template. I have found three and it now compiles, here is the template

#include <map>
#include <utility>
template <class T> class foo{
public :
foo(T bar1, T bar2){
_bar1.push_back(bar1);
_bar2.insert( std::pair<T,T>(bar1,bar2) );

[Code] ....

The errors I believe I have found are as follows: the vector library has not been added, the map requires two type arguments rather than one and the object which is created in main doesn't pass any values to the constructor. I fixed all of these errors and the code now compiles without errors, however the problem asks for five.

View 1 Replies View Related

C++ :: Compiling Errors In Template Class?

Mar 22, 2014

what my compiling errors mean, and what I should do to fix them: The following is my header & Implementation files. Note, the purpose of this class is a built in Array.

Header File:

#ifndef ARRAY_H
#define ARRAY_H
#include <iostream>

[Code].....

View 5 Replies View Related

C# :: Definition Errors After Changing Name Of Class

Jan 31, 2014

I changed the name of my Invoice class to 'Application' and then it generated errors such as follows

Error9'Invoice.Invoice' does not contain a definition for 'Documents' and no extension method 'Documents' accepting a first argument of type 'Invoice.Invoice' could be found (are you missing a using directive or an assembly reference?)c:userskeildocumentsvisual studio 2013projectsinvoiceinvoicewritefile.cs1840Invoice

Error3'Invoice.Invoice' does not contain a definition for 'Run'C:UsersKeilDocumentsVisual Studio 2013ProjectsInvoiceInvoiceProgram.cs1921Invoice

I have added my classes here, lso I have added the sln to this post.

using System;
using System.Collections.Generic;
using System.ComponentModel;

[Code].....

View 5 Replies View Related

C/C++ :: Finding Errors In Class Template?

Nov 18, 2014

I have to find at least 5 errors in the following class template. I have found three and it now compiles, here is the template

#include <map>
#include <utility>
template <class T> class foo{
public :

[Code]....

The errors I believe I have found are as follows: the vector library has not been added, the map requires two type arguments rather than one and the object which is created in main doesn't pass any values to the constructor. I fixed all of these errors and the code now compiles without errors, however the problem asks for five.

View 2 Replies View Related

C++ :: Making Class Constructor Within Namespace And Keep Getting Errors

Mar 25, 2013

I'm trying to make a class constructor within a namespace and I keep getting errors like: "'<variable>' is a nonstatic data member of class '<class>'" for when I try to setup parameters, and "Incomplete type is not allow" whenever I try to write out my function definition. Here's what I'm doing:

namespace test {
class blah;
} class blah {
typedef int var[5];

[Code] .....

Also I'm unsure why there is a parameter of 'const blah &' when I mouse over blah(); (using Visual Studio 2010) within the class definition. It tells me 'blah::blah(const blah &)' and I am unsure where the parameter comes from. How can I resolve these issues?

View 4 Replies View Related

C++ :: Class / Header File Related Errors

Sep 22, 2014

Here's my class/header, and Visual studio Output.

Injection point/instantiation.

int main() {
Player player;

Call to a public method:
while(!isWin("x", board) && !isWin("o", board) && whoGoesFirst == "p") {
printBoard(board);
board = player.playerTurn(board);

[Code] .....

Output:
1234
1
1> Player.cpp
1>c:users
sccdocumentsvisual studio 2012projectsprog 2100 - assignment 1prog 2100 - assignment 1player.h(10): error C2143: syntax error : missing ';' before '<'
1>c:users
sccdocumentsvisual studio 2012projectsprog 2100 - assignment 1prog 2100 - assignment 1player.h(10): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:users
sccdocumentsvisual studio 2012projectsprog 2100 - assignment 1prog 2100 - assignment 1player.h(10): error C2238: unexpected token(s) preceding ';'

View 2 Replies View Related

C++ :: Template Class Type - Unresolved Link Errors

Jun 25, 2013

I'm getting unresolved link errors when I attempt to compile.

dNode.h

#ifndef DNODE_H
#define DNODE_H
template <class T>
class dNode {

[Code] ....

ERROR:
Error1error LNK2019: unresolved external symbol "public: __thiscall dStack<double>::dStack<double>(void)" (??0?$dStack@N@@QAE@XZ) referenced in function "void __cdecl stack_test(void)" (?stack_test@@YAXXZ)main.objprog09
Error2error LNK2019: unresolved external symbol "public: virtual __thiscall dStack<double>::~dStack<double>(void)" .......

View 3 Replies View Related

C++ :: Compiler And Linker Errors For Linked List Class And Application

Aug 31, 2014

I am trying to write a program that will take a list of integers from a file and write them to another text file. I've been banging my head at this for days trying to get it to compile as it is riddled with linker and compiler errors.

**************************header*************************

#ifndef LINKEDLIST_H
#define LINKEDLIST_H
#include <iostream>
using namespace std;
template <class T>
class linkedList {

[Code] ....

View 6 Replies View Related

C++ :: Read User Input To Determine Different Discounts By Number Of Units Sold - Errors In Program

Jun 23, 2014

it will not run and im not sure why. I have a couple of errors, but I'm not sure why.

Here is my code.

//Reads input from user to determine different discounts by number of units sold

#include <iostream>
#include <string>
using namespace std;

int main() {
//Declaration and Initialization of variables
int quantity;
double discount,price = 99.00,totalCost;

[Code] ....

View 1 Replies View Related

C :: Program Reading / Writing Files

Dec 10, 2013

program that I am working on. I want to use fgets() in my program so I could handle multiple words from a text(to be able to handle spaces). I get a weird result when running the program.

Code: #include <stdio.h>
#include <stdlib.h>
//#include "kim.h"
#include <string.h>
[code]....

View 4 Replies View Related

C :: Writing Log File In Multithread Program

Oct 20, 2014

I'm currently finishing writing some small application. I want to be able to log important information about the program execution to a logfile, and I have several questions.

First of all - I'd prefer to make the part that logs information to a file separate from the code I've already written. So, what interface should I expose to the rest of the program? Is one function void log(const char*); enough?

Another thing that came to my mind; my program runs two threads, and I want to be able to write to the log file from both threads, so the question is: Should I make sure that the writing to the file is mutually exclusive?

And if so, whose responsibility is it to make the logging to the file thread-safe? The actual part that does the logging (void log(const char*) for that matter), or the parts of the program that calls log(const char*) ?

And lastly, and probably less importantly, where is it customary to save the logfile? (the user's home folder maybe?)

View 3 Replies View Related

C++ :: Writing A Program Without Using Any Type Of Container

Jan 19, 2014

How to write a program without using any type of container .

View 4 Replies View Related

C++ :: Writing Output Of A Program To A File?

Mar 27, 2013

basic code for writing output of a program to a file? I can't seem to find it online and I need it to complete a project.

View 2 Replies View Related

C++ :: Writing A Program To Calculate Grades

Apr 22, 2014

Writing a program to calculate grades... My algorithm is long, so I only posted the part that gives me trouble. When classes== 1,2,4, or 5, the program runs fine. but it terminates when classes == 3.

if (classes==3) {
do {
cout<<"Enter the Letter grade for 1st class. (USE CAPS)"<<endl;
cin>>grade1;

[Code].....

View 3 Replies View Related

C++ :: Writing A Program That Outputs To Dat File

Nov 18, 2013

I have been asked to write a program to grade several multiple-choice exams. The exam has less than 80 questions, each answered with a letter in the range of ‘a’ through ‘f’. The data are stored on several files such as exam1.dat where the first line is the key, consisting of a string of n characters (0<n < 80). The remaining lines on the file are exam answers, and consist of a student ID number, a space, and a string of n characters.

The program should have a while loop in the main routine to ask users input a data file name through keyboard. In this way, the program has a capability of repeatedly asking for a new data file in each while loop until users input a key word “exit”. Once “exit” is encountered, the while loop terminates and your program ends. A typical input exam data file (exam1.dat) looks like:

abcdefabcdefabcdefab
1234567 abcdefabcdefabcdefab
9876543 abddefbbbdefcbcdefac
5554446 abcdefabcdefabcdef
4445556 abcdefabcdefabcdefabcd

Apply strlen( ) or the length( ) of string to the first line of the above data file for determining the number of questions in the problem. If a student gives more answers than necessary, the extra answers will be automatically truncated. On the other hand, if a student provides less number of answers, the remaining unanswered questions are considered as being answered wrongly.

After users input an exam data file, your program should ask users to input another grade-curving file name (e.g., gradeCurving.dat). This second file contains the information to convert a percentile score to a curved grade in levels of ‘A’ through ‘E’. For instance, a grade-curving file takes the following format: a curved alphabetic grade, a space, a percentile grade served as marker.

A 90
B 80
C 70
D 60
E 50

The above information means that ‘A’ = 90 through 100; ‘B’=80 through 89; ‘C’=70 through 79; ‘D’ = 60 through 69; “E”=50 through 59; For the remaining grades, you can assign an ‘F’.

Furthermore, in each while loop in the main routine, your program should ask users to input an output file name such as score1.dat. The output file will store the scores for each student in a format: student ID number, a space, a percentile score, and a curved grade in ‘A’ though ‘E’. The program should also compute and display the following statistics for the graded answers: Average score, Maximum score, and Minimum score.

A typical output on a data file looks like:

1234567 90% A
9876543 85% B
5554446 95% A
4445556 75% C
5551112 80% B
Statistics:
Average Score: 85%
Minimum Score: 95%
Maximum Score: 75%

This Is what I have so far. It compiles fine and everything but when I input the files it says "There was an error opening the corresponding files. Check input name perhaps?" and it exits out ....

#include "stdafx.h"
#include <iostream>
#include <string>
#include <fstream>
#include <assert.h>
using namespace std;
int openfiles(ifstream& infile, ifstream& curvingfile, ofstream& outfile);
void Size(ofstream&,int,string);

[Code] ....

View 11 Replies View Related

C++ :: Program Crash Writing To Binary File

Feb 17, 2014

cant write to binary file

#include <stdio.h>
#include <stdlib.h>
typedef struct {
int number;
} something;
void main() {
int numbers[10]={1,2,3,4,5,6,7,8,10,12};

[Code] .....

View 2 Replies View Related

C++ :: Writing A Program That Requires Exception Handling

Nov 24, 2013

writing a program that requires exception handling. if an error occurs, i what the program to go back to the begging of the loop. i tried using break but that just makes the program crash when it receives a bad input. how do i do this? this is what i have so far (this part of the program any ways)

while (! quit)
{
// Output phone book menu
cout << endl

[Code].....

View 1 Replies View Related

C/C++ :: Writing Program That Will Calculate Employee Salary?

Jan 31, 2014

I am having some trouble with my class assignment. We need to write a C program that will calculate the employee salary. There are 5 employees that will need to be calculated. We are required to use a loop also.

So far this is what I have but I am receiving errors when running the program.

#include <stdio.h>
int main() {
int clock_num; /* employee clock number */
float gross; /* gross pay for week (wage * hours) */
float hours; /* number of hours worked per week */
float wage; /* hourly wage */
/* Prompt for input values from the screen */
printf ("This is a program to calculate gross pay.

[code]....

View 3 Replies View Related

C++ :: Writing A Program That Finds The Probability Of Moves?

Sep 13, 2013

I'm writing a program that finds the probability of moves a Knight can make on a chess board. The program asks the user to enter the row and the column and the program is supposed to output how many possible moves the Knight can make, but the output is wrong. Example(if I enter row 1 and column 1 the output is 8 and it should be 2) I know the problem is with my if statements.

#include <iostream>
using namespace std;
int chess(int a, int b) {
int x =a;
int y = b;
int sum=0;

[code]....

View 3 Replies View Related

C# :: Writing A Program To Display Multiplication Table?

Feb 3, 2015

i need the output to display the product of every whole number from 1-3 in a table format.

this is the code i have so far. i know some brackets are missing but i just pasted the meat of the code. when i run the program i keep getting the number 1 displayed in a straight line going on forever

int multiply1 = 1;
int multiply2 = 1;
while(num1<=3)
{ // num1*num2;
//num1 = 0;
while(num2<=3)
{ Console.WriteLine(multiply1*multiply2);
if(num1>=3)
{ Console.Write();
}
}
num1++;
}

View 2 Replies View Related

C++ :: Writing Program That Asks User To Input Number?

Sep 11, 2013

im writing a program that asks the user to input a number 1-10 and will transform it into the roman numeral of that number but it seems that its not after the user inouts the number nothing will output

#include <iostream>
#include<iomanip>
using namespace std;

[Code]....

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved