1. Construct a class diagram that can be used to represent food items. A type of food can be classified as basic or prepared. Basic food items can be further classified as meat, fruit, veg or Grain. The services provide by the class should be the ability to enter data for new food, to change data for food and to display existing data about food.
using this class definition write a main program to include a simple menu that offers the following choices:
1. Add food 2. Modify Food 3. Delete Food 4. Exit this menu
2. Read a list of numbers from a file and then print them out in reverse order. State whether the list is palindromic or not.
Write a program that prompts the user to enter three integer values, and then outputs the values in numerical sequence separated by commas.
So, if the user enters the values 10 4 6, the output should be 4, 6, 10.
If two values are the same, they should just be ordered together.
So, the input 4 5 4 should give 4, 4, 5.
Code: #include "std_lib_facilities.h" int main() { cout << "Enter three integers, separated by space: "; int a, b, c, temp1 = 0, temp2 = 0; cin >> a >> b >> c;
[Code] ....
My first solution has a bug, so here's the corrected solution, written using only features I have learned in the first three chapters:
Code: #include "std_lib_facilities.h" int main() { cout << "Enter three words, separated by space: "; string a, b, c, temp; cin >> a >> b >> c;
Implement a recursive function named void printBack(DoublyLinkedNode<T>* node) for the class DoublyLinkedCircularList which will print out the elements in the list from back to front. The function is initially called with the first node in the list. You may not make use of the previous(prev) links
This is my solution where I got 2 out of a possible 3 marks:
template<class T> void DoublyLinkedCircularList<T> :: printBack(DoublyLinkedNode<T>* node) { if(node->next == NULL) //Correct- 1 mark return 0; else printBack(node->next); //Correct - 1 mark cout << current-> element << " "; }
Using the array to accept 10 testscore. Calculate and print the highest, lowest, fifth test score entered and all the test score entered in reverse order.
How i would get it to print the highest,and lowest and in reverse order. I'm confused as to what to do...
I am working on a small simple program my program fills up a air plane with customers there is 2 levels 1 and 2 and it will put that person in the spot depending on being picked.
So far i made a boolean airplane with 10 spots I can enter 1 person into the airplane with no problem but then after he sits down i get a infinite loop? I assume i maybe have to use the continue statement I feel like there is something simple that im missing i want to add more people. here is what i have
I have an exercise that asks me to print numbers at random from the following set (using only a single statement):
2, 4, 6, 8, 10
Here's my statement:
Code: cout << (2 + rand() % 9) << " ";
which prints numbers at random between 2 and 10, now I can use the modulus operator in an if...else statement to print only even numbers but the exercise specifically requires using only one statement, can that be done using the conditional operator? and if not then how?
I am trying to write a program that will make a pattern of stars. The last line is really tripping me up. I have to make the code only using the printf("*"); printf(" "); printf("/n"); statements once. I want to accomplish this with a for loops and if statements.
It is supposed to look like this:
* - 5 spaces before * * * - 4 spaces before * * * * - 3 spaces before * * * * * * * - 0 spaces before *
This is what I've tried so far:
main() { int i, j, k; i=1; j=1;
[Code]....
here are the links on codepad [URL]
I think my first approach is way off. But I think I am on to something in the second link. I'm trying to print the "*" and extra 2 times on the fourth line. In the second link the compiler appears to be ignoring the || operator. Is my syntax incorrect in the second attempt? How should I change my if statement to make this pattern work?
I'm trying to enter an 'x' and 'y' coordinate on only one line separated by a comma. But I keep getting a syntax error. Here are the lines of code I'm using. This has to be simple. What am I doing wrong with this code?
Code: cout<< "Please enter the x and the y coordinates of the first point,"<<endl; cout<< "use a comma to separate them. " <<endl<<endl; cin>> "You entered: " >>x1>>",">> y1 >>"for the first point" >>endl;
I have been trying to read a comma separated .txt file into an array and print it to console in C++. The txt file consists of two columns of double type data. For some reason the program runs, but gives blank output in the console. I want to know if I am doing something wrong. So far this is what I have:
#include <iostream> #include <fstream> #include <string> using namespace std; int main() { int i=0; double x[10]; double y[10]; string line;
How to print a string in reverse order(for example: "today is Wednesday " to "Wednesday is today"). My professor said we should begin with a null string and build it one word at a time.
#include <iostream> #include <fstream> #include <string> using namespace std; int nwords(string);
Basically this is what i need to do. Write a program that reads a number from the keyboard, separates it into its individual digits and prints the digits to screen, each on its own line followed by the same number of stars as itself.
For example, if the number is 2339 the program should print
9 ********* 3 *** 3 *** 2 **
So far i have managed to separate the number and have them on different lines, but how to implement the stars onto each line with the number!
My code so far:
int main() { int n; printf("number? "); scanf("%d", &n); while (n > 0) { printf(" %d
I have two vectors of float that I need to sort in reverse order. reverse() seems to work for one of them, but not the other. I have toggled between sort() and reverse(). for one vector, the expected behavior is seen and the order reverses. For the other, there is no change in order.
This is very simple code, so it's hard to imagine what is going wrong.
You can see that the order of the first vector did not change. Am I right in suspecting that the numbers are too similar for what ever method reverse() uses to determine the difference between values?
The next step for my project is to take data from a file, and create a new file with the same data, but in reverse order. If a file has the following values:
1 2 3 4 5
The program should create a new file with the following values:
5 4 3 2 1
Seems pretty straight forward, yet I am hitting a snag when I try to compile my program:
The following errors occur when I try to compile the fore mentioned code:
intrev.c: In function 'main': intrev.c:25: warning: unused variable 'out' intrev.c: At top level: intrev.c:39: error: expected identifier or '(' before 'while'
[Code] .....
Now I am not concerned with "unused variable 'out'" as it is used, just in a for loop. Is this a problem?
I'm not entirely sure why it's giving me the error at line 39. I've gone over this a couple times and it doesn't look like I've missed any methods which need to be closed. Maybe I've missed something?
I'm also not sure why I am getting an error when I try to close the opened files. I've done this before in the same manner, but without errors. Not sure why I am now, but my guess is that it has something to do with the error on line 39.
I was trying to reverse a linklist in reverse direction using the recursion. I was able to reverse n - 1 element but it is not printing the first one. Below is my code.
Code:
typedef struct linklist { int data; linklist *next; };
void add(int data,linklist **node) {
[code]....
This is happening since recursion is starting from second node, which is due to reason not printing the first one when recursion print values from stack once
node != NULL
Condition is met.
Currently I am using below statement for printing the first element;
reverse_recur(node); printf(" Print In Reverse Order %d ",node->data);
I need fastest method to reverse order of bytes in my char array.
For example i have:
unsigned char buf[8]; // consider data stored in buf is 88 77 66 55 44 33 22 11 // how to reverse it to: 11 22 33 44 55 66 77 88 // currently i can do it by equal assignment , i make another buf like: unsigned char buf_ok[8];
[Code] ....
// This does reverse the bytes as i want but its very slow , i am looking for fast method ..
or better yet, what if I want it to not matter whether the columns are separated by commas or spaces? is there any way to do this? If there is no way to read in both comma-separated and space-separated elements simultaneously then I would prefer just comma, rather than the space separated which my code is able to read now. What modifications would I have to make to my code to make this work? This is my code to reference.
I'm trying to use a priority queue sorting in reverse order to take a vector or 2d array. The problem is that I want to sort by the vector/array cell value but keep the reference to the vector/array index of the value. I don't know quite howto keep them both related so when I pop. I can find the corresponding cell.
I am attempting to read in a file that has 4128 sets of 21 numbers separated by commas and write it into an array. I now know that in order to use fseek, I have to make my array a character array, but I need my function to read in decimals (ex: 0.172635). I'm reading in
I need to create a program that reads some numbers, and calculate them on a separated subroutine, and the return of this subroutine must be the sum of all the numbers. I'm getting an error but I can't figure out why =/
#include <iostream> using namespace std; int calc(int val, int qtd){ int sum=0; for (int cont=0; cont<qtd; cont++) sum=sum+val; return sum;
[Code]...
The error that I'm getting is on the line 22.
The error message: "invalid conversion from 'int*' to 'int' [fpermissive]