I have an assignment that asks me to write a program which reads all lines from a text file (one by another), reverses them and write to the same file. I also have a pseudocode with which I have to work and it is as follows:
While the end of the file has not been reached
pos1 = current get position Read a line. If the line was successfully read pos2 = current get position Set put position to pos1. Write the reversed line. Set get position to pos2.
I have tried many things and the code misses letters. Below you can see my code:
Code: #include <iostream> #include <fstream> #include <string> #include <cstdlib> using namespace std; int main() { fstream file; file.open("output.txt");
[code]....
This is the text with which I have to work:
Mary had a little lamb Its fleece was white as snow And everywhere that Mary went The lamb was sure to go.
And this is what I get:
bmal elttil a dah yraM Itswons sa etihw saw eceelf Antnew yraM taht erehwyreve d T.og ot erus saw bmal eh
I've been having problems with my loop that asks if the user wishes to continue or not. The required input should either be 'y' or 'Y', or 'n' or 'N'. Anything else should be counted as invalid, and repeat the prompt for input. The first few times I ran my program, the compiler does not read it as a loop. The next few times just won't work properly.
Here is the prompt: Code: void question() { char option; printf(" Do you want to continue? {Y|N) "); scanf("%c", &option);
[Code] ......
As it is, it immediately runs the else option, but otherwise runs just fine. I suspect it could be because I have not specified a size for the option variable, but I try doing that, and the prompt relegates everything to the else.
(And also, here's the rest of the code. Basically, it just assigns a value to the letters of the word (a/A = 1, b/B = 2, etc.), adds these values, and determines if a word is prime or not based on the sum.)
Code: #include <stdio.h> #include <string.h> #define size 30 int main() { char letter, word[size], lower, upper, option; int i, value, ans = 0, a, choice = 1;
Working on a basic class program and I'm generating two compiler errors that I'm not sure how to fix. Header file, implementation cpp and main cpp are shown below. The specific errors are shown after the code.
The file generates the second error, C2228, at lines 37-41 and 43. Basically where I tried using the second created object. Error message is "left of '.setFirstName' must have class/struct/union"
Working on a solution involving inheritance. The whole solution is pretty massive at this point so I'll just focus on the problem areas. I'm getting a lot of "redefinition" and "undefined class type" compiler errors, including C2370, 2011, 2504, and 2027, in Benefit.h, Employee.h (the constant members are a big occurance) I'm also getting 2027 and 2079 in EmployeeMain.cpp. with my Benefit and Employee object calls.
Clearly I missed something in about how to code this correctly. Sadly the course textbook focuses on general OOP theory instead on the accompanying C++ syntax.
My compiler (GCC) keeps expecting an expression where it shouldn't in 1 specific piece of my code:
int zxcNewWindow( HWND parent, TCHAR *text, zxWINDOW *kid, UINT style, int x, int y, int w, int h, int type ) // right here { *kid = zxDefWINDOW;
The project contains only 2 files right now and the settings are just the default for an empty Code::Blocks 12.11 project. Both files are in UTF-8 format (tried in ASCII too), I just cannot see why this is not compiling correctly. I'll post the files in the next two posts.
Edit: For those of you who didn't get what the error was from the above here's the full log:
mingw32-gcc.exe -Wall -g -DzxDEBUG -c C:MePrjscppzxGUImain.c -o objmain.o C:MePrjscppzxGUImain.c: In function 'zxcNewWindow': C:MePrjscppzxGUImain.c:39:10: error: expected expression before '{' token Process terminated with status 1 (0 minutes, 0 seconds) 1 errors, 0 warnings (0 minutes, 0 seconds)
I am trying to run this source code but i am getting the compiler error Expression Must Have a Constant Value. I tried making both the variables x and y constants and assigned them to a significantly big number but then i am getting the error expression must be a modifiable lvalue.I have made comments in the code in front where Visual Studio is giving me the syntax error (red squiggly line).
#include<iostream> #include <string> #include<cmath> using namespace std; int main(){ int x; int y;
I am having problems compiling this program. line 29 causes the error "left operand must be l-value".
// chap5proj.cpp : Defines the entry point for the console application. // # include <stdafx.h> # include <iostream> using namespace std; int main() { double mph, time, disPerHour, milesTrav;
Full disclosure: this is an exercise from "Sams Teach Yourself C++ in 24 Hours" by Jesse Liberty and Rogers Candenhead. This refers to Chapter 9 (Hour 9 Activity 1)
I created a class called Point, in Point.h
I created a class called Rectangle in Rectangle.h and Rectangle.cpp
If I create an int main() function in Rectangle.cpp (that includes Rectangle.h), I can compile Rectangle.cpp and run the resulting program. Fine.
Question:
I create a separate file called main.cpp. I include Rectangle.h. But now the compiler complains.
Code: $ g++ main.cpp -o main /tmp/cc38JIph.o: In function `main': main.cpp:(.text+0x26): undefined reference to `Rectangle::Rectangle(int, int, int, int)' main.cpp:(.text+0x32): undefined reference to `Rectangle::getArea() const' collect2: ld returned 1 exit status If I can create a class in Point.h and use it in Rectangle.h, why can I not just use Rectangle in main.cpp?
And the files, of course:
file: main.cpp Code: #include <iostream> #include "Rectangle.h" using std::cout; using std::endl;
Well, I thought I had this program working but now I'm getting the above referenced compiler error. The program is just a basic user interface. It is for a classwork assignment.
The program is to accept user information as a string, convert it (if needed) to either the int or double variable, and then display the result. I'm using stringstream convert to make the change between types, but I'm not sure if I'm using it right (that might be what's causing the error, I'm not sure). Line 36-37 generates the error.
Code: #include <iostream> #include <iomanip> #include <sstream> using namespace std;
Having issues with program to create a shape area calculator with circle square and rectangle. the uml goes as follows:
Where the UML has shape as the abstract class with public area():double, getName():string,and getDimensions:string, rectangle derived from shape with protected height, and width, and a public rectangle(h:double, w:double), followed by a derived square from rectangle with just a public square(h:double), and finally a circle derived from shape with a private radius, and a public circle(r:double).
[URL]
Have linked my program and it is giving me the following compiler errors:
error: 'qdebug' was not declared in this scope line 15 of main
error: cannot declare variable 'shp' to be of abstract type 'shape' line 22 of main
error: expected primary-expression before ')' token lines 29 -31 of main
(note previously had qstring as a header file yet changed to string since I was getting error qstring was not declared in this scope.)
I am trying to compile the files file1.c and file2.c using Mingw (gcc)
///////////////////// header.h //////////////////// #ifndef header #define header int variable; #endif
[Code] ....
I would have expected a multiple defnition error when linking the two .c files. as in both the files, with the 'int variable' command, the variable 'variable' is defined (memory allocated) and during linking the linker doesnot know which variable to link to.
I get an error though when i use "int variable =123;" in the header file instead of the "int variable;" statement. i dont understand as in both the cases the variable is defined (memory is allocated) and the linker should give a multiple definition error.
I have been implementing a Hash Table class made, and ran into a bit of a problem in my Delete function. I have the hash table made up as
vector<list<HashNode<T,X>>> m_Table
My problem is when I iterate through the vector, and then the list in that current element to try and find the Node I want to delete, the STL list class gives me the error:
Error1error C2678: binary '==' : no operator found which takes a left-hand operand of type 'HashNode<T,X>' (or there is no acceptable conversion)
I've just recently started to learn C++, and I'm encountering some errors I can't seem to figure out.
InventoryItem.h:
Code: #pragma once class InventoryItem { public: InventoryItem(string name, int amount); ~InventoryItem(void); string getName(void); int getAmount(void);
While trying to redo everything in c i have an error on a do while loop and i don't understand i've corrected everything else but i don't understand why the error occurs even though it says how to fix it it says error expected ) before token -line 18 part of code
Code:
int main(){ Beep (523,1000); // sound at 523 hertz for 1 000 milliseconds char cPresent; do }
[code]....
this is just extra bits i've added on to the assignment but I've worked on the c++ code for a week now i have less than a day to redo it
I am just starting out with loops and I have run into an syntax error and for the life of me I cant find out the issue. Before it has been an issue of me forgetting to close my brackets but I am pretty sure I did that this time. I am trying to have the program keep looping the main menu until the user inputs a correct number.