Post a C or C++ program that you have written
From C++ to PHP, debugging to webhosting; help and discussion about writing your latest program to running your website. NOT for help when your PC won't work.
| Announcements | Posted on | |
|---|---|---|
| Ask me ANYTHING - Andrew O'Neill - Buzzcocks comedian, amateur occultist, veggie... | 22-05-2013 | |
-
Post a C or C++ program that you have written
I think there should be a thread where people share their ideas like this. I am very new to C++ so I wont post anything until later, assuming this thread becomes popular.
Post a C or C++ program that you wrote that you think could be useful to someone else browsing this thread.
-
Re: Post a C or C++ program that you have written
What do you mean by useful? Also "ideas" is very different to code.
What exactly are you looking for?
As you asked though, I have a few C/C++ apps of varying quality on my sourceforge account. -
Re: Post a C or C++ program that you have writtenCouple of little programs, MS Office, Firefox, nothing major(Original post by The_Last_Melon)
I think there should be a thread where people share their ideas like this. I am very new to C++ so I wont post anything until later, assuming this thread becomes popular.
Post a C or C++ program that you wrote that you think could be useful to someone else browsing this thread.

All I've done is a little maths tool which was basically a little window with buttons for popular maths symbols like Pi, square root, powers etc. and there was a drop-down menu to let you select the active window for input (e.g. you could select your open Word document for the text to appear in there rather than the Notepad file you have open). I had it installed on my old computer but forgot to back it up! All gone
-
Re: Post a C or C++ program that you have written
I wrote a program to automate my college software audit.
WinAudit will generate .txt for every pc in my college, all of them are stored in the same directory. My program will read very single line from every single file in that directory and generate an excel table as a report (a report for one lab). -
Re: Post a C or C++ program that you have written
(sorry I couldn't get line numbers)
#include <cassert>
#include <cstdlib>
#include <iostream>
class Cpu {
public:
virtual int dummy( int, int ) {}
private:
virtual int add_( int a, int b ) { return a + b; } /* A */
virtual int sub_( int a, int b ) { return a - b; } /* B */
virtual int mul_( int a, int b ) { return a * b; } /* C */
virtual int div_( int a, int b ) { return a / b; } /* D */
virtual int mod_( int a, int b ) { return a % b; } /* E */
virtual int and_( int a, int b ) { return a & b; } /* F */
virtual int or_( int a, int b ) { return a | b; } /* G */
virtual int xor_( int a, int b ) { return a ^ b; } /* H */
};
int main( int argc, char* argv[] ) {
typedef int (Cpu::*Memfun)( int, int );
union {
Memfun fn;
unsigned char ptr[6];
} u;
Cpu cpu;
u.fn = &Cpu::dummy;
assert( argc == 4 );
int p1 = atoi( argv[ 1 ] );
int p2 = atoi( argv[ 3 ] );
char op = argv[2][0];
assert( op >= 'A' && op <= 'H' );
u.ptr[0] = 1 + 4 * ( op - 'A' + 1 ); // Don't look here!
std::cout << "The answer is " << ( (cpu.*(u.fn))( p1, p2 ) ) << std::endl; -
Re: Post a C or C++ program that you have written
Here's one that should be familiar (fibonacci anyone?)
#include <iostream>
using namespace std;
int main()
{
int count;
// long long is HUGE! alast and blast are initialized.
long long alast, blast, sum, n;
int totamnt;
alast = 0;
blast = 1;
// Determines place in the sequence.
cout << "Enter time: ";
cin >> n;
cout << "\n";
// Determines inital amount (what to multiply final sum by).
cout << "Enter total amount: ";
cin >> totamnt;
cout << "\n";
switch (n)
{
// Catches 0 before it outputs a negative number.
case 0: cout << "0"; break;
// Catches 1 before it outputs 0.
case 1: cout << 1 * totamnt; break;
default:
// Determines place in the sequence.
for (count= 0; count < n-1; count++)
{
// "Rolls" numbers around to make the sequece work.
sum = alast + blast;
alast = blast;
blast = sum;
};
// Outputs the place in the sequence multiplied by the initial ammount.
cout << "\n" << sum * totamnt << " is the total amount."; break;
}
return 0;
}
----- -
Re: Post a C or C++ program that you have written
Link/Cut trees

Code:// solves Codeforces #123 problem E #ifndef SOURCE_IS_SPLICED #include <unordered_set> #include <unordered_map> #include <functional> #include <algorithm> #include <iostream> #include <numeric> #include <cstring> #include <cstdio> #include <string> #include <vector> #include <cmath> #include <queue> #include <stack> #include <list> #include <set> #include <map> using namespace std; typedef long long ll; #ifdef seventeen #define localfun(x) x #else #define localfun(x) #endif void run();int main(){localfun(freopen("e.in","r",stdin));ios::sync_with_stdio(false);run();} #endif ll const l=100000; ll const mod=1000000007; struct LinkCut{ LinkCut *p,*l,*r; ll weight; ll sum; inline LinkCut(LinkCut* p=nullptr): p(p){ l=r=nullptr; } inline bool root(){ return not p or p->l != this and p->r != this; } inline void push(){ sum = weight + (l? l->sum: 0) + (r? r->sum: 0); } inline void increase(ll by){ splay(); (weight+=by)%=mod; push(); } inline void rot(LinkCut* LinkCut::*a,LinkCut* LinkCut::*b){ if (not root()) (p->l==this?p->l:p->r)=(this->*a); (this->*a)->p=p, p=(this->*a); (this->*a)=(p->*b), (p->*b)=this; if (this->*a) (this->*a)->p=this; if (l) l->push(); if (r) r->push(); push(); } inline void rotate(){ if (p->l==this) p->rot(&LinkCut::l,&LinkCut::r); else p->rot(&LinkCut::r,&LinkCut::l); } inline void splay(){ push(); while (not root()){ if (not p->root()) p->p->push(); p->push(); push(); if (not p->root()) ((p->l==this)==(p->p->l==p)? p:this)->rotate(); rotate(); } push(); } inline void link(LinkCut* x){ splay(); p=x; p->splay(); } inline void expose(){ for (LinkCut* i=this,*j=nullptr; i; j=i,i=i->p){ i->splay(); i->l=j; i->push(); } splay(); } inline ll depth(){ splay(); return sum; } inline LinkCut* findroot(){ expose(); LinkCut* x=this; while (x->r) x=x->r, x->push(); return x; } }; LinkCut tree[l]; ll w[l]; void run(){ ll res=0; int n; cin>>n; for (int i=0; i<n; i++){ int k; cin>>k; for (int j=0; j<k; j++){ ll v,x; cin>>x>>v; --x; while (v<0) v+=mod; ll plus=tree[x].findroot()->depth(); ll y=tree[x].findroot()-tree; tree[y].link(tree+i); tree[y].increase(v+plus); (res+=v+plus)%=mod; } } cout<<res<<endl; } -
Re: Post a C or C++ program that you have written
Its an open source project, and others have contributed a lot more than myself, but this C++ server software.
-
Re: Post a C or C++ program that you have writtenThey are both incredibly useful, and both heavily used.(Original post by rock_climber86)
hmmm, i want to learn c or c++. Which one should i learn? Which one is more useful? i've got some vba programming experience but that's it
You can't really go wrong with either. I suppose C is conceptually simpler to understand (no Object Orientation), but so might be a slightly better choice if you are going to self-teach yourself. With C there are arguably less bad habits you can get yourself into. -
Re: Post a C or C++ program that you have writtenis C a subset of C++? If i learn C, say, can i progress onto C++ or is the syntax totally different as is the code between vba and C?(Original post by Fallen)
They are both incredibly useful, and both heavily used.
You can't really go wrong with either. I suppose C is conceptually simpler to understand (no Object Orientation), but so might be a slightly better choice if you are going to self-teach yourself. With C there are arguably less bad habits you can get yourself into. -
Re: Post a C or C++ program that you have writtenI'd start with C then move onto C++. They are very closely related, so much so that when you first go to C++ from C you'll barely notice the difference. But when you start using C++'s features that C doesn't have you'll realise the difference between them.(Original post by rock_climber86)
hmmm, i want to learn c or c++. Which one should i learn? Which one is more useful? i've got some vba programming experience but that's it
-
Re: Post a C or C++ program that you have writtenFor the most part, yes. C++ is an extension of C.(Original post by rock_climber86)
is C a subset of C++? If i learn C, say, can i progress onto C++ or is the syntax totally different as is the code between vba and C?
The syntax is almost identical where they overlap, although obviously the new features C++ adds require new syntax. Almost all valid C code is valid C++ code.
I should note, however, that C++ being an extension of C does not mean that C is worse or less useful, just different. -
Re: Post a C or C++ program that you have written
I've got an idea - you could have a 'game' thread similar to this where the OP posts a simple program and then challenges the forum to achieve a simple goal (i.e. solving a maths problem) using a program. The firsty reply solves the problem and then challenges the forum to solve another and so on. I suppose it would take a while for people to respond but if we could get it working then it would be good.
-
Re: Post a C or C++ program that you have writtenThis is actually a brilliant idea, although maybe the program could be stored in a github repo to avoid pasting the entire program/changes into replies.(Original post by When you see it...)
I've got an idea - you could have a 'game' thread similar to this where the OP posts a simple program and then challenges the forum to achieve a simple goal (i.e. solving a maths problem) using a program. The firsty reply solves the problem and then challenges the forum to solve another and so on. I suppose it would take a while for people to respond but if we could get it working then it would be good. -
Re: Post a C or C++ program that you have writtenI originally meant seperate programs, but it would be even better if it was one program being continuously improved with relevant enhancements. I cba settting up such a thread though - maybe you could?(Original post by Fried Sock)
This is actually a brilliant idea, although maybe the program could be stored in a github repo to avoid pasting the entire program/changes into replies.
