00001 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). 00002 // All rights reserved. 00003 // This component and the accompanying materials are made available 00004 // under the terms of "Eclipse Public License v1.0" 00005 // which accompanies this distribution, and is available 00006 // at the URL "http://www.eclipse.org/legal/epl-v10.html". 00007 // 00008 // Initial Contributors: 00009 // Nokia Corporation - initial contribution. 00010 // 00011 // Contributors: 00012 // 00013 // Description: 00014 // Contains definition of functions defined in the CAdder class. 00015 // 00016 00017 00018 00023 #include "adder.h" 00024 00030 CAdder* CAdder::NewL(CLongNumber* aLongNumber) 00031 { 00032 CAdder* self = new (ELeave) CAdder(aLongNumber); 00033 return self; 00034 } 00035 00039 CAdder::CAdder(CLongNumber* aLongNumber):iLongNumber(aLongNumber) 00040 { 00041 } 00042 00047 TInt CAdder::Add() 00048 { 00049 // Set the iterator to the start of the list. 00050 iLongNumber->InitializeIter(); 00051 00052 // Initialize sum to 0. 00053 TInt num; 00054 TInt sum = 0; 00055 00056 // Iterate the list. 00057 // The iterator is pointing to a valid node. 00058 // Get the digit represented by this node. 00059 while(iLongNumber->GetNumber(num)) 00060 { 00061 // Update the sum. 00062 sum += num; 00063 // Go to the next digit. 00064 iLongNumber->Slide(); 00065 } 00066 00067 return sum; 00068 } 00069 00073 CAdder::~CAdder() 00074 { 00075 } 00076
Copyright ©2010 Nokia Corporation and/or its subsidiary(-ies).
All rights
reserved. Unless otherwise stated, these materials are provided under the terms of the Eclipse Public License
v1.0.