565 Posted Topics
Re: On my laptop: cout: 0.89 printf: 67.89 Operating System: Windows 7 Ultimate 64-bit (6.1, Build 7601) Service Pack 1 (7601.win7sp1_gdr.120330-1504) Processor: Intel(R) Core(TM) i3 CPU M 330 @ 2.13GHz (4 CPUs), ~2.1GHz Memory: 4096MB RAM I'll try on my PC, to see if there's any difference between them. | |
Re: If the code relies on printing out remainders in base 16, why don't you use the hex part of the cout? int main(){ int remainder=159%16; cout<<remainder<<endl; cout<<hex<<remainder<<endl; cout<<159%16; return (0); } This will print the letter `f`. For more information about printing out or working with hexadecimal check this website: … | |
Re: Hope this helps. Note that I didn't write it in Turbo C++, you'll have to make the right adjustments. Also, you might change the `char file[256]` line with `char* file="C:\Documents and Settings\Migs\Dextop\test.txt"` so that it will open the file directly from your dextop. I took the liberty to make some … | |
Re: as **deceptikon** pointed out: #define radius Here you must give radius a value (as the point of this assignment illustrates: "Program illustrating the use if #defines"). `#defines` works as macros, here you gave `PI` a value which will be held throughout the entire program, thus doing the same with radius. … | |
Re: Not to be pricky or such but **markwiering**, you should listen to these fine gentlemen, because they really know what they are talking about. Frankly when I look at your source code I see a lot of if statements whereas some other implementation would have saved your processor time/life etc. … | |
Re: like **iamthwee** said, you should use a class in which you'll store as elements each of your requirements: So you'll need some strings for the project name, supervisor name and student name, and some integer for the id. After you do that class, let's call it `ToBeStored`, you should use … | |
Re: here, this might help you: #include <iostream> #include <string> #include <fstream> #include <sstream> using namespace std; int main(){ string file; cout<<"Insert file: "; cin>>file; ifstream fin(file.c_str(), ios::in); string line; if(!fin){ cerr<<"Can't read file "<<file<<endl; return (0); } else{ cout<<"Text: \n"; while (getline(fin, line,' ')){ stringstream token(line); int to_hex; token>>hex>>to_hex; cout<<(char)to_hex<<' … | |
Ok, so, this code snippet is a reply to this thread: http://www.daniweb.com/software-development/cpp/threads/425821/prime-number-c From what I understood form the OPs request, is that, he wanted an algorihm which would check for prime numbers in a given range, applying these conditions: a number is to be considered valid if: a. the number … | |
Re: Another thing you could do, having in consideration the fact that your problem, as you identified, resides in the main menu part of your program, you could change the approach of the menu. You could use instead of the `switch case` statements a simply string validation menu: #include <iostream> #include … | |
Re: This might help you: #include <iostream> using namespace std; int main(){ cout<<'a'+0; //prints out the ascii number of character 'a' return (0); } | |
Re: I don't think there is that kind of tool, but searching on google won't kill you. And on the other ideea of yours, making an online convertor, you being just a beginner in java and c/c++ would make things harder. Maybe it's better to start with something easier, maybe from … | |
Re: A slightly different approach, or not... here it goes anyway: /* * game.cpp * game.cpp is licensed under GNU GENERAL PUBLIC LICENSE * Created on: Aug 15, 2012 * Author: sin */ #include <iostream> #include <string> #include <stdio.h> #include <stdlib.h> #include <time.h> using namespace std; int plays=0, comps=0; int computer(){ … | |
Re: Here's the pseudocode. class Rectangle int height, width public Rectangle(initial_height, initial_width) height=initial_height width=initial_width end_Rectangle getArea() getArea=height*width end_getArea end_class main height=input height width=input width Rectangle rt(height, width) print Area=rt.getArea end_main | |
Re: > public String changeBadWords(String string, Collection<String> badWords) { > for (String badWord : badWords) { > string = changeBadWord(string, badWord); > } > return string; > } > private String changeBadWord(String sentence, String badWord) { > return sentence.replace(badWord, censor(badWord)); > } > private String censor(String badWord) { > for (String … | |
Re: As **np complete** said, post some code first, so that we see you've tried. We won't solve your homework, because that won't help you at all. If you want to become a programmator you'll have to start programming, and these kind of homeworks are just the thing you need in … | |
Re: And have you even try to solve this homework? Or are you hoping for us to solve it, and than to just present the result to your teacher? Show us that you've tried, show us where are the issues and than we'll try to help you. | |
Re: Maybe you can think your program as this: a class Library in which you hold objects books and some kind of connection (talking about the loan part) with the customers. This connection will be for the loan part, as each object book can be loan or is loaned. Each book … | |
Re: Have a look at this snippet: http://www.daniweb.com/software-development/cpp/code/427923/simulation-of-functions-from-stlvector | |
Re: Here's the pseudocode: function getpass() char choice char passwd[lenght] do @ ask for password passwd<-input @ ask for a repeat choice<-input while choice = 'n' end_do_while end_function | |
Here's some simulation of the basic push_back and pop_back functions from stl vectors, "inspired" by this thread: http://www.daniweb.com/software-development/cpp/threads/427912/question-about-a-simple-vector-class-template | |
Re: as **deceptikon** said, you should stick with the std::string objects. #include <iostream> #include <string> using namespace std; int main(){ string choice; cout<<"A or B?"; cin>>choice; if (choice=="A") cout<<"A\n"; else if (choice=="B") cout<<"B\n"; else cout<<"Invalid command.\n"; return (0); } Here's a quick example of how you can compare strings, via the … | |
Re: C++ tutorial about file i/o: http://www.cplusplus.com/doc/tutorial/files/ C++ tools: [I/O library](http://www.cplusplus.com/reference/iostream/) [manipulators](http://www.cplusplus.com/reference/iostream/manipulators/) Time retrival: [C time](http://www.cplusplus.com/reference/clibrary/ctime/ctime/) [C time library](http://www.cplusplus.com/reference/clibrary/ctime/) File parshing: [File parshing example.](http://cs.dvc.edu/HowTo_Cparse.html) Other Daniweb threads: http://www.daniweb.com/software-development/cpp/threads/426579/file-io-.txt-read-error#post1824833 http://www.daniweb.com/software-development/cpp/threads/426316/search-whole-file-for-a-complete-string-c#post1823366 | |
Re: Easy done via strings. #include <iostream> #include <string> using namespace std; int main(){ string name; cout<<"Insert your name: "; cin>>name; cout<<"Hello "<<name<<".\n"; return (0); } | |
Re: Here, this sould fix it: #include<iostream> #include<string> using namespace std; int main(){ char array[5][5]; int i=0,j=0; string z[5]={"abdg","ygur","guqh","asdf","sent"}; for(i=0;i<5;i++) for(j=0;j<4;j++){ array[i][j]=z[i][j]; cout<<"\narr["<<i<<"]["<<j<<"]="<<array[i][j]; } for (int i=0;i<5;i++) array[i][4]=0;//clears the buffer for unwanted characters. for(i=0;i<4;i++) cout<<"\narr="<<array[i]<<endl; return (0); } I changed the array type to char, as **ravenous** suggested, because you're accessing … | |
Re: At first, as all websites, Facebook had an 'enemies' button, just as the 'friends' button, but soon after the grand opening of the website, it's core was failing due to the fact that no1 could put Chuck Norris on their enemy list, not even on a virtually list.:D | |
Re: as **pyTony** said, `file` as a variable name is bad because `file` as a name is used inside Python do denote i/o file stream objects. | |
Re: think of this like this: #include <iostream> using namespace std; int main(){ char a='a'; cout<<"Char a: "<<a<<endl; char* p=new char(a); cout<<"Char* p(points to a): "<<*p<<endl; char** pp=new char*(p); cout<<"Char** pp (points to p which points to a): "<<**pp<<endl; return (0); } Also you can do a 2x2 matrix out of … | |
Re: And your question is? I can tell you straight from the beginning: We don't solve homeworks, but we can help. Liniar search algorithm, this is the pseudocode: number_of_times<-0 i<-0 intput<-given input while input!=array[i] do number_of_times++ i++ end_while if number_of_times=20 then print element not found end_if It's not that hard to … | |
Re: try this: [useradd](http://nixcraft.com/getting-started-tutorials/3293-create-new-user-account-ubuntu-linux-command-line.html#post23762) just found it outa google... | |
Re: And presumably you want it in a nice format, with some comments rite? Well, I think that's not gonna happen. You see, this sounds like a homework/lab assignment, and here, at Daniweb, we don't solve homeworks for others. Out goal here is to help those who are in need or … | |
This is a program which I made back in the beginnings when I was trying to figure out how to work with strings, and how to work with files. This is suppose to format a C++ code, for example if the syntax of an if statement is if (condition) { … | |
Re: Well, line 42 and 45 you're trying to declare a function in another function, and that's not allowed. void RMatrix::RepMatrixf() { const int MAX = 100; // PROBLEM STARTS BELOW void RepMatrix (int NDR, int size, int PosIR, int calls) but by looking to your code, you want to do … | |
Re: Have you checked this thread? [Click Here](http://www.daniweb.com/software-development/c/threads/50370/starting-c-) it's at the top of the C threads. | |
Re: The basic ideea of your problem is called a [Permutation](http://en.wikipedia.org/wiki/Permutation). There are numerous methods of doing that, maybe check in the CS department of the link for some concrete algorithms. >How do I start? Or better yet Where? take **WaltP**'s example... | |
Re: Here's the pseudocode, a little bit of thinking wouldn't have hurt you would it? subalg. printChristmasTree(){ for (i<-0, i<5) do for (j<-0, j<=i*2) do for (k<-5, downto i) do if (j=0) then print space end_if print '*' end_for print new line end_for @print base of the tree end_for end_Subalg. | |
Re: Here's a quick example: #include <iostream> #include <string> #include <fstream> using namespace std; int main(){ string filename; ifstream fin(filename.c_str(), ios::in); if (fin.is_open()){ string line; while (getline(fin, line)){ cout<<line; } } else cout<<"Invaild file."; return (0); } Getline will take the input from the file either till '\n' appears or the … | |
Re: Since you're posting in a C++ thread, why don't you use C++ functions to work with? I'm just saying, it might help you. | |
Re: > int argc,char *argv[] 1st of all, why do you use that? I don't see in your program nothing related to that. 2nd: this is an example of how you should do it, if I understood corectly. Here I'm not using any char 2x2 array, but I do simulate one. … | |
Re: well by fork() you'll create a child process. the pipe works like this: on one end you write something and on the other end you read. the pipe is done like this, I'll write it in pseudocode: int a2b pipe(a2b) if fork()==0 then write(a2b[1], information, size) exit(0) endif wait(0) read(a2b[0], … | |
Re: Have you checked this code snippet? http://www.daniweb.com/software-development/cpp/code/425707/simple-string-to-int-and-int-to-string-conversion | |
Re: I will hant it in pseudocode, it's not too hard to figure it out by yourself: i<-0; while i != given_input_number do j<-0 while j != i do print * increment(j) end_while print new line increment(i) end_while as cscgal said you have only the outer loop, so you need to … | |
Re: Type in the cmd the following lines: gcc --version g++ --version make --version If either 1 of them sais that the program is not found, you'll have to reinstall MinGW. | |
Re: Here's a way of doing it using string, and C++ items: #include <iostream> #include <sstream> #include <string> #include <vector> using namespace std; int main(){ string str="HEllo*world*hello.", split; vector<string> all; istringstream token(str); while (getline(token, split, '*')){ all.push_back(split); } for (int i=0;i<(int)all.size();i++){ cout<<all[i]<<endl; } return (0); } The all vector will contain … | |
![]() | Re: As **mike_2000_17** said: we can help you only if you show us some code, or some attempts of doing the actual homework. In your program you'll need a container in which you'll store the integers. You will need after that another 3 distinct integers, one which will hold the smallest … |
Re: Well depending on what you think when you're talking about input redirection. This can be either putting the input of a file into an array, or putting the input given from the keyboard into an array? You got that % a.out < inputfile off this site: http://www.cs.bu.edu/teaching/cs111/spring-2000/file-io/ but did you … | |
![]() | Re: > if pl_move == "skip" or "Skip" or "SKIP": As pyTony said, the if statement will be always true. You'll need to do it like this: if pl_move == "skip" or pl_move=="Skip" or pl_move=="SKIP": the condition impose that you should check the equality for every choice of pl_move. As for … ![]() |
Re: I think you can't pass a vector as `const vector<string> &vect` and still resize it, because the `const` argument insures that the element passed will not be change, whereas resizeing will change it, so it will yield a compiler error. Passing the vector as `vector<string> vect` will pass a copy … | |
Re: **firdousahmad** indeed, but the difference between `int main() { return(0);}` and `void main(){}` is alot more than the return type. Read more about this question [here.](http://www.cplusplus.com/forum/beginner/19979/) `#include <iostream>` includes in your program the library iostream (Standard Input / Output Streams Library). Read more about that [here.](http://www.cplusplus.com/reference/iostream/) About the `using namespace … | |
Re: Here's a quick and dirty way to store the items position. I'm using a vector for that. #include <iostream> #include <vector> using namespace std; int main(){ int numbers[100]; vector<int> divisors; for (int i=0;i<100;i++){ numbers[i]=i+200; } for (int i=0;i<100;i++){ if (numbers[i]%7==0) divisors.push_back(i); } for (int i=0;i<(int)divisors.size();i++){ cout<<"Number divisible with 7: "<<numbers[divisors[i]]<<"\nPosition … | |
Re: **Archuom**: there are plenty examples on the forum, just type file i/o in the search box. **laith al hamed** what is your business here? If you do have some questions please make a thread of your own in which you explain your needs and struggles. |
The End.