I have two classes, productListType and buyerListType, that are each basically linked lists. To create the linked list for an object of productListType, I successfully wrote a non-class function createProductList to read the product data from a text file. The class definition for buyerListType has a data member productBoughtRecord that is of type productListType to aggregate the details of the products purchased by a particular buyer during transactions. I decided to make productBoughtRecord a pointer since the contents of this data member would wax and wane over the course of several transactions, depending on the amount and frequency of payments made by the buyer. I have provided a rough sketch of the class below:
I'm similarly trying to write a non-class function createBuyerList to load the record of customers from a text file. How do I determine what the value of the formal parameter p in member function setCustomerInfo is, in order to be able to set the data member productBoughtRecord? take into consideration that an object of class buyerListType would have multiple buyers with varying amounts of products purchased.
I want to display data from text file in list view and in tree view root will be file name, but i dont know how to do it, the problem is with displaying text file data in list view, i don't know anything about that. text file data is very simple. It is just a square matrix of double values like:
But the output rows are not aligned as shown in the attached picture. There a two problems.
1. Data rows don't align with the header row. 2. When the first element of a row changes to two digits, the other elements are shifted.
According to MSDN [URL] ...., CString::Format() works the same way as printf(). I wrote a small program using printf() to do the same thing, and the output in the console are perfectly aligned.
I have been writing a fairly simple turn based rpg game in c++ and at the moment it has a 2d integer array for the map, which I can display using periods for the blank areas and letters for the various people in the game, and I am trying to figure out how to upgrade to a tile based display.
i want to display all the contents of a file excluding one based on user input say i have 4 records in the file numbered 1 to 4....the user chooses 2 to exclude it outputs records 1,3,4,4 when it should be records 1,3,4 what am i doing wrong here is the code.its basically displaying the last record in the file twice
We're assigned a project working with classes and fractions. My goal is to display a fraction in proper from based on 2 arguments passed to a class member function proper();
My strategy was to utilize the greatest common factor between the 2 arguements, then divide both the numerator and denominator by that number and then it would display.
The program actually runs, but only seems to divide the numerator and not the denominator. This in return makes my other class member functions have incorrect comparisons and sums.
Code: #include<iostream> #include<conio.h> class Fraction { friend void compare(Fraction a, Fraction b); friend void sum(Fraction a, Fraction b);
I am working on my first RPG. Nothing fancy so far... I haven't developed a story or anything, just trying to get the gameplay hammered out. Anyway, I have a couple of NPCs and Items and I was wondering how I should program these interactive spots. I'm unsure whether I should loop the Room info or continue forward with if statements. With Items, I want to prevent the player trying to use the option to get the item again (after you pick up the item, the option is gone. Here are a couple examples of where I have the problem
else if(playerloc == 3) { cout << "There is a hooded figure in the corner. " << "The person waves you over. ";
[Code]....
What I want to do after the character interaction is complete is continue forward with the option to go south or east. I could return to the room menu, or continue by coding forward and allow the option to go east or south with more if-else-if chains..
In the next bit, I want to program the item to be picked up and then the treasure chest will be empty.
else if(playerloc == 5) { cout << "There is a treasure chest in the Northwest corner of this room. "
I have written a text based web browser from scratch. Meaning that I'm not using libcurl in any way to retrieve the web pages.Now I'd like to add HTTPS functionality to it, but I can't seem to find a guide like Beej's Guide to Network Programming related to HTTPS.
I'm currently creating a text-based RPG, to get myself back into learning C++ again. The problem seems to be with the if-else ladder of statements, the user selects which race they wish to play as, which as a result creates the appropriate object for that race.
This is the character selection option code:
std::cout << "Please select a race: Human [1], Elf [2], Dwarf [3] or Orc [4] "; std::cout << "Race selection: "; std::cin >> race_selection; std::cin.ignore(); switch (race_selection) {
[Code] .....
The problem here is, regardless of which race I use using the above switch statement, the Human object always seems to be created, instead of the object for the desired race.
#include <iostream> #include <fstream> using namespace std; int main() { int r = 0; int c = 0; int num[17][15] = { 0 }; [Code] ...
// Here is my code for displaying the data from the text file into a 2d array and height next to it, but I am not able to diaplay the height from 60 to 76 next to the row of the 2d array, as shown in the table below. This is my program:
Recently the health authorities have listed a new way to calculate the body mass index (BMI) of an individual. Values of 20 – 24 are classified as normal, 25-29 as overweight, and 30-34 as heavy.
The table below is a portion of a typical BMI table.
How you'd type yes or no scenarios for a text based RPG? And I mean a really basic like 'you see ..... what do you do?'. Also, how would you finish a code like this.
I am working on a text-based RPG game and I want to allow the player to save his progress. So I need to save several integers and a string. And my problem starts here "How can I save integers and load them?". I read the tutorial but I dont understand. I need to write a function to save game?
I am trying to make a very simple text based game and I want the players to be able to name their characters. Thus, I am trying to have the game ask "how many players will be playing:" and then taking that number (X) and create a place to store that information. I'm trying to get the game to ask, "What is the name of Player1?" Then once the user enters the name it would ask "What is the name of Player2" and that cycle would continue until PlayerX has entered their name. Is what I am doing close?
Here are the errors:
error C2143: syntax error : missing ';' before 'string'(ln 29 col 1) Error2error C2678: binary '<<' : no operator found which takes a left-hand operand of type 'std::basic_istream<char,std::char_traits<char>>' (or there is no acceptable conversion) (ln 30 col 1)
int NumberOfPlayers; if (Response1 == "Yes") { cout << " How many players will be joining us on our adventure: ";
Write an interactive text based menu interface (using a loop) that will allow the user to
Enter a task or assignment Display all of the tasks that are in the file Find a task by Course Quit For each task, you need to keep track of:
Course Name that it is for (e.g., CS162) Description of the assignment (e.g., Finish Lab 2) Due date (e.g., 9/26/2009)
Allow the program to keep looping until user wants to quit. When the program starts, it should load the tasks from external file ("tasks.txt") into memory. When user enters the three items of a task, the program needs to read them in, save them in memory and eventually write them to the external data file ("tasks.txt"). The file format could look like: (The ';' is used as a delimiter or field seperator.)
Some Implementation Requirements:
Write at least four functions WITH arguments for this assignment. Use struct named Task to model task Use array of structs to model the collection of tasks. Hint: In this assignment, the description and course name may have multiple words in it. Therefore, you now SHOULD read using the 3 argument version of get. Watch out. When using the 3 argument version of get you need to make sure to remove the delimiter or newline. Therefore, anytime you read (even a confirmation message), make sure to eat the newline! Make sure to have a delimiter written between each item in the file – like a newline. This will be important when you read the information back from the file.
This is my code so far:
#include <iostream> int main() { char cname[25],desc[20];
Here is the assignment... Write a program to generate a report based on input received from a text file. Suppose the input text file student_status.txt contains the student’s name (lastName, firstName middleName), id, number of credits earned as follows :
Doe, John K. 3460 25 Andrews, Susan S. 3987 72 Monroe, Marylin 2298 87 Gaston, Arthur C. 2894 110
Generate the output in the following format :
John K. Doe 3460 25 Freshman Susan S. Andrews 3987 40 Sophomore Marylin Monroe 2298 87 Junior Arthur C. Gaston 2894 110 Senior
The program must be written to use the enum class_level :
The function deriveClassLevel should derive the class_level of the student based on the number of credits earned.
The first namespace globalType tys should derive the class level based on a two year school policy. And the second namespace globalType fys should derive the class level based on a four year school policy.
Four Year School Policy: Freshman 0-29 creditsSophomore 30-59 credits Junior 60-89 creditsSenior 90 or more credits
Two Year School Policy: Freshman 0-29 creditsSophomore 30 or more credits
My main question is did I use the namespaces and enum correctly? And my second question is whats the best way to input the data from the text file? This is really where I get stuck.
Write a program to generate a report based on input received from a text file. Suppose the input text file student_status.txt contains the student’s name (lastName, firstName middleName), id, number of credits earned as follows :
Doe, John K. 3460 25 Andrews, Susan S. 3987 72 Monroe, Marylin 2298 87 Gaston, Arthur C. 2894 110
Generate the output in the following format :
John K. Doe 3460 25 Freshman Susan S. Andrews 3987 40 Sophomore Marylin Monroe 2298 87 Junior Arthur C. Gaston 2894 110 Senior
The program must be written to use the enum class_level :
The function deriveClassLevel should derive the class_level of the student based on the number of credits earned.
The first namespace globalType tys should derive the class level based on a two year school policy. The second namespace globalType fys should derive the class level based on a four year school policy.
So I basically did it in parts and got everything working and then had to make the namespace so I had this:
with this i keep getting an error saying tys::deriveClassLevel: must return a value and tys::fys::deriveClassLevel: must return a value. I have been messing around with this part and struggling I thought I used the namespace to run the if statements with the criteria for the years of school. Basically I have been stuck for awhile and trying to change things around but I cant seem to get it to work.
Player is given choice of x number of Races This choice changes the player's base stats. Then player is given a choice of x number of Classes (archer, warrior, etc.) This choice determines how the player's stats will change upon leveling up.
how to stop outputting data based on a user input. The text file is as follows:
1. a 2. b 3. c
and the code I'm using is as follows:
int main (){ string line; int search; cout << "Enter a number from 1-3" << endl; cin >> search; search++; ifstream myfile ("example.txt");
[Code]...
What I want to do is to just output number 1 (the whole line) if the user enters number 1. However, I get an error on the second condition w/c is the "&& line!= search"
I'm trying to make a Quiz program based on C++'s Data File Handling capablities. I've attached the code in .txt file and I wonder why I'm getting the error identifier bScience cannot have a type qualifier?
I have a problem I am working on where I need to sort some data based on the values of a string of bits. The strings look like this,
010000001110000000
there are 18 bits, 1 means a feature is present, 0 means the feature is absent.
Each of these string has 4 on bits. I need to sort them such that I have the longest possible runs with 3 of the same on bits. It doesn't matter which 3 bits are on, I am just looking to order them in blocks with the longest possible runs. As a second step, the ordered blocks will be sorted by size large>small.
The following data is ordered like I need it to be.
Code: // block 1, run of 12, keys 1,2,11 are identical (key 12 is also identical) 011000000001100000 011000000001100000 011000000001100000 011000000001100000
[Code] .....
This is the sort order that I am looking for. I need to be able to take a list of the bit strings in any particular order and sort them into the order above. The algorithm would need to recognize that there are 4 on keys and then look for groupings of three common on keys.
This is more of an algorithm question than one about specific implementation in code. I generally assume that most programming problems have been solved one way or another, so I don't know much about analyzing and manipulating strings of bits.
Is there a standard method for this kind of pattern recognition?
Ok I'm trying to create matrix of data that I can add values to based on a reading that I will get from a DVM. I'm using a 3d vector to do this. I need to keep track of the serial number, the day and within day I need to take two readings at different temps, this will continue for 7 days.
The rows of my 3d vector will be the days, the colums will be the serial numbers the depth will be the reading at the different temps.
What I need to do is compare the first element (days) and when it is greater then or equal to 4 I will perform calculations of the readings. So all I want to do is compare the first element of the vector, How do I do this?
I have a piece of code that sorts data based on some metric. The some metric is something I now want to make flexible so I can easily switch between and compare metrics. To do this, I want to pass the function to use as a parameter to the method that does the sorting (and other stuff). However, I'm having problems figuring out the syntax. Also, I think my [temporary] organization of code is violating a lot of basic code design principles.
To make the function pointer passable, I defined the "typename" in the header where the function is located (it is part of a struct, "Data"):
// Below the struct definition of Data typedef double (Data::*CostF)(unsigned l, double W) const;
The two example functions I want to use are defined in that struct ("Data"):
// Inside the struct definition inline double someExampleCost(unsigned l, double W) const { // Returns some basic calculation }
The function that uses it is part of a different class (that holds a reference to the first class, in case that matters; I feel like I'm doing something odd here, because I'm binding a member function in the definition/passing, but never referencing the object). It looks like this:
// Inside another class ("Foo") inline void DoSomeStuff(double& ECost, double& TCost, CostF cost) { // Irrelevant stuff here std::sort(vector.begin(), vector.end(), [&](unsigned a, unsigned b){ return (*cost)(a, W) < (*cost)(b, W); }); // More irrelevant stuff here }
The error shown is "operand of "*" must be a pointer". If I remove the '*': [code]return cost(A, W) < cost(b, W);
the error becomes: "expression must have a (pointer-to-)function type."
The call to this function is, currently, just in the main function, as I'm just testing before I wrap it into real code. It looks like this:
// In main Foo bar; // Make an object of the struct that has the "sorting" function CostF costFunction = &Data::someExampleCost; // Bind to the Cost function bar.DoSomeStuff(varA, varB, costFunction);
This bit shows no errors by itself. So, my questions:
a) Clearly I'm missing the insight into Function Pointers. I'm comfortable with regular pointer stuff, but I can't wrap my head around FPs, partly due to the awkward syntax.
b) I'm very uncomfortable with the fact that I'm binding a member function of a class, but never try to reference an actual object of that class. This is probably a big part of why it's not working, but I can't seem to bind a function belonging to a specific object. I thought of doing
// In the main again Data d; // Construct the object, which contains big lookup tables Foo F(d); // Construct the object, which only holds a reference to a Data object CostF costFunction = &d.someExampleCost; // Bind to the Cost function of that object
but that doesn't work ("a pointer to a bound function may only be used to call the function").