Post your C/C++ Programs Here

Status
Not open for further replies.

Sykora

I see right through you.
Re: Post ur C/C++ Programs Here

The only way is to create a new list, going through each node of the previous list and inserting it at the beginning of the new list.

eg :

Code:
Node *p = head->next;
Node *revHead = head;
head = head->next;
revHead->next = NULL;
while (p != NULL) {
    p = p->next;
    head->next = revHead;
    revHead = head;
    head = p;
}

Now you have a new list, with revHead as the head node.
 

nithinks

True Techie
Re: Post ur C/C++ Programs Here

Sykora said:
The only way is to create a new list, going through each node of the previous list and inserting it at the beginning of the new list.

eg :

Code:
Node *p = head->next;
Node *revHead = head;
head = head->next;
revHead->next = NULL;
while (p != NULL) {
    p = p->next;
    head->next = revHead;
    revHead = head;
    head = p;
}

Now you have a new list, with revHead as the head node.

Fine.. but lets assume that list contains some 1 lack records.. so if thats the case this program will create an overhead... any optimistic code?
 

Sykora

I see right through you.
Re: Post ur C/C++ Programs Here

How does it create overhead? It isn't creating new nodes, just reinserting them in a new list.
 

nithinks

True Techie
Re: Post ur C/C++ Programs Here

Sykora said:
How does it create overhead? It isn't creating new nodes, just reinserting them in a new list.

You are right.. but is it not possible to do that without creating another list?
 

Nav11aug

In the zone
Re: Post ur C/C++ Programs Here

try this..

Code:
node *revList(node *head)
{	
	if(head==NULL)
		return head;
		
	node *p,*q,*r;
	p=head;		

	while(p!=NULL){
		r=q=p->next;
		if(q!=NULL){
			q->next=p;
			p=r;
		}		
	}
	
	head=p;
	
	return head;	
}
 

Glen Apayart

Right off the assembly line
Re: Post ur C/C++ Programs Here

My brother always use my admin account because i leave my pc on sometimes when im away or sleeping for a while.

So, I made a simple conditional statement for my brother to be reminded about the account he is using. By changing the icons of my .exe from his favorite game icon. hehe :D

Code:
#include <iostream>
using namespace std;

int main()
{
    char Ans;

    cout << "Hello!\n";
    cout << "The program you have choosen has been disabled by the admin,\n";
    cout << "Please use your own account,\n\n";

    do{
    cout << "do you want to exit (y/n)? ";
    cin >> Ans;

        if(Ans == 'n' || Ans =='N')
            cout << "Could you please leave me now...\n\n";
        else if(Ans == 'y' || Ans == 'Y')
            break;
        else
            cout << "Invalid Entry!\n\n";
    }
    while(Ans != 'y' || Ans != 'Y');
        system("cls");
        cout << "Thank you!" << "\n\n";
        cout << "Press any key to exit...";

    return 0;
}
 

aditya.shevade

Console Junkie
Re: Post ur C/C++ Programs Here

^^ ROFL :-D:-D:-D:rolleyes:

By the way, I am working on a Library Emulation project. For my submissions. A mini project. The problem is that everyone has to do this one only (Library) and our mam wants 80 different source codes. (I am sure mine will be unique ;-)).

It does not use file handling. I will post it here soon.....

Aditya

PS @ Glen Apayart, I just saw you signature... You are a newbie you say, but still. There is no void main in ISO C/C++ :-D
 

BBThumbHealer

BlackBerry Guru ! :)
Re: Post ur C/C++ Programs Here

i m making my project for class xii...its heading its completion , last thing that i wanna do is like i m making a calendar and a billing dept. calculation center , i wanna print that on a paper using the printer ! is this possible ? if yes , then plz buddies help in coding !
 

arunks

Hey here is the aks
Re: Post ur C/C++ Programs Here

Glen Apayart said:
My brother always use my admin account because i leave my pc on sometimes when im away or sleeping for a while.

So, I made a simple conditional statement for my brother to be reminded about the account he is using. By changing the icons of my .exe from his favorite game icon. hehe :D

Code:
#include <iostream>
using namespace std;

int main()
{
    char Ans;

    cout << "Hello!\n";
    cout << "The program you have choosen has been disabled by the admin,\n";
    cout << "Please use your own account,\n\n";

    do{
    cout << "do you want to exit (y/n)? ";
    cin >> Ans;

        if(Ans == 'n' || Ans =='N')
            cout << "Could you please leave me now...\n\n";
        else if(Ans == 'y' || Ans == 'Y')
            break;
        else
            cout << "Invalid Entry!\n\n";
    }
    while(Ans != 'y' || Ans != 'Y');
        system("cls");
        cout << "Thank you!" << "\n\n";
        cout << "Press any key to exit...";

    return 0;
}

hey what does system("cls") do...?
is this a inbuilt function...? how and what is its usage..?
is this used to execute shell commands i mean dos commands..
 

QwertyManiac

Commander in Chief
Re: Post ur C/C++ Programs Here

arunks said:
hey what does system("cls") do...?
is this a inbuilt function...? how and what is its usage..?
is this used to execute shell commands i mean dos commands..
Yeah it is used to execute commands, or launch other programs too perhaps.

Your current running program halts when this is called, and continues only after the command called completes execution. System() makes the code OS-Dependent.

*www.phim.unibe.ch/comp_doc/c_manual/C/FUNCTIONS/system.html
 

QwertyManiac

Commander in Chief
Re: Post ur C/C++ Programs Here

Typedef is commonly used to give any Data Type a new name.

Like for example:
Code:
#include<iostream>
int main()
{
    typedef int a; [I] // Thus, [B]a[/B] refers automatically to an integer[/I]
    a abc=1, def=0; [I]// Creates two variables of type int,
                              // as the typedef above shows[/I]
    cout<<"ABC = "<<abc<<" DEF = "<<def<<endl;
    return 0;
}
This is very useful while working with a lot of classes, or structures. You can name them comfortably or for different usages (Like we use Position and List names in a clear Linked List algorithm but both are essentially the same structure, just used with a different name to aide understanding).
 
Last edited:

shyamno

Ambassador of Buzz
Re: Post ur C/C++ Programs Here

can anyone give me a tutorial on how to ....do user authentication using C..is it possible...

suppose I ..have created a website ...where a member have to login...so how do I check the user verification.....

Any source code...
 

BBThumbHealer

BlackBerry Guru ! :)
Re: Post ur C/C++ Programs Here

BlackBerry7100g said:
i m making my project for class xii...its heading its completion , last thing that i wanna do is like i m making a calendar and a billing dept. calculation center , i wanna print that on a paper using the printer ! is this possible ? if yes , then plz buddies help in coding !

wud anyone lyk to help in the above case ?
 

aditya.shevade

Console Junkie
Re: Post ur C/C++ Programs Here

I have been having a problem. And someone please help me as soon as you can.

I have designed a project to be submitted in the college for submission purpose. Now, the project is a library database. I have developed a little part and I am attaching it.

When I showed the program to our teacher, she said that I must use inheritance in the program. The problem is that I don't know much about it, and from whatever I read and tried to gather in the last 2 days, I have reached a conclusion that inheritance cannot be used effectively in this case.

So please please tell me where and how to use it. Else I will have to submit this one only.

Aditya
 

QwertyManiac

Commander in Chief
Re: Post ur C/C++ Programs Here

Sometimes in colleges, 'effective' isn't the word, its 'you have to'. So implementing it even for a basic thing would satisfy them. Just saying ..

I don't understand 'make' stuff in your files, you use Ajunta? Is coding them all into one file not a good procedure? And the use of header files etc? Wait, how do I even compile it? :confused: Need some enlightenment on this.
 

aditya.shevade

Console Junkie
Re: Post ur C/C++ Programs Here

QwertyManiac said:
Sometimes in colleges, 'effective' isn't the word, its 'you have to'. So implementing it even for a basic thing would satisfy them. Just saying ..

I don't understand 'make' stuff in your files, you use Ajunta? Is coding them all into one file not a good procedure? And the use of header files etc? Wait, how do I even compile it? :confused: Need some enlightenment on this.

I use anjuta. You guessed right. To compile it... I dunno the sommand line method. But if you have Anjuta, then create a new project and add the files in that project. Then click on auto generate the project.

Then compile, make and build to execute.

And after reading professional C++, I have reached the conclusion that creating different files is the best way to make the program easy to understand, modify and expand.

Try if you can, else I will send you the entire project by mail. The compressed (tar.bz2) file is about 1000KB.

Aditya
 

[xubz]

"The Cake is a Lie!!"
Re: Post ur C/C++ Programs Here

Has anyone correctly implimented Brent-Salamin algorithm for computing Pi? I never was able to get it right :(

(Only thing i've done is Leibniz method of Pi, thats easy, but it takes insane amount to just calculate 10 decimal places accurately! :-/)
 

The_Devil_Himself

die blizzard die! D3?
Re: Post ur C/C++ Programs Here

^^lol me too.I am wondering how to compile it using Dev c++.
BTW you are very good at programming Aditya and a clean programmer.
 
Status
Not open for further replies.
Top Bottom