473,804 Members | 3,272 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Please correct my c++ Code

6 New Member
Expand|Select|Wrap|Line Numbers
  1. //////////////////////////////     LinkList.cpp 
  2.  
  3.  
  4. #include "LinkList.h"
  5.  
  6.  
  7. /* The LinkList class implementation*/
  8.  
  9. /* Constructor */
  10. LinkList::LinkList() 
  11. {
  12. headNode   =   new Node();
  13.     headNode->setNext(NULL);
  14.     currentNode   =   NULL;
  15.     lastCurrentNode  =   NULL;
  16.     size   =   0;
  17. }
  18.  
  19. /* add() class method */
  20. void   LinkList::add (int   addObject) 
  21. {
  22.     Node *   newNode   =   new   Node();
  23.     newNode->set(addObject);
  24.     if( currentNode   !=   NULL )
  25.     {
  26.         newNode->setNext(currentNode->getNext());
  27.         currentNode->setNext( newNode );
  28.         lastCurrentNode   =   currentNode;
  29.         currentNode   =   newNode;
  30.      }
  31.      else
  32.      {
  33.     newNode->setNext(NULL);
  34.     headNode->setNext(newNode);
  35.     lastCurrentNode   =   headNode;
  36.     currentNode   =   newNode;
  37.       }
  38.       size ++;
  39. }
  40.  
  41. /* get() class method */
  42. int   LinkList::get() 
  43.     if (currentNode  !=  NULL) 
  44.      return   currentNode->get(); 
  45. }
  46.  
  47. /* next() class method */
  48. bool   LinkList::next() 
  49. {
  50.     if (currentNode  ==  NULL)   return  false;
  51.  
  52.     lastCurrentNode  =  currentNode;
  53.     currentNode  =  currentNode->getNext();
  54.     if (currentNode == NULL || size == 0) 
  55. return  false;
  56.     else
  57.     return  true;
  58. }
  59.  
  60. /* Friend function to traverse linked list */
  61. void traverse(LinkList list)
  62. {
  63.     Node* savedCurrentNode  =  list.currentNode;
  64.     list.currentNode  =  list.headNode;
  65.  
  66.     for(int i = 1; list.next(); i++)
  67.     {
  68.         cout << "\n Element " << i << " of the list is  " << list.get()<< endl;
  69.     }
  70.  
  71.     list.currentNode  =  savedCurrentNode;
  72. }
  73.  
  74. /* Friend function to add Nodes into the list */ 
  75. LinkList addNodes(){
  76.  
  77.             LinkList list;
  78.             int count = 0;
  79.             cout  << "\n Enter the length of the LinkList you want to create: ";
  80.             cin>>count;
  81.             int temp;
  82.             for(int i = 0; i < count ; i++)
  83.             {
  84.                 cout  <<"\n Enter the Element No # "<<i+1<<": ";         
  85.  
  86.                 cin>>temp;
  87.  
  88.                 list.add(temp);
  89.  
  90.             }    
  91.             cout  <<  "\n     List size is = "  <<  list.size  <<'\n';         
  92.  
  93.             return list;
  94.             return list.size;
  95.  
  96.       //////////**********    MEAN()  ***********/////////     
  97.         }
  98. void LinkList ::mean()
  99. {
  100.   if (headNode == Null)
  101.   cout<<"\n Undefined Value";
  102.   else
  103.   {
  104.       Node *temp = headNode;
  105.         int mean = temp->get();
  106.         int total;
  107.         //show content of node
  108.         while(temp !=Null)
  109.         {
  110.             if (mx<temp->get() )
  111.             total = total + temp->get;
  112.             //move into next node
  113.             temp = temp->getNext();
  114.         }
  115.         mean=total/list.size; 
  116.         cout<<"\n Mean of List is "<<mean;
  117.     }
  118. }        
  119.  
  120.    //////////**********    MAX ()  ***********/////////   
  121.  
  122. void LinkList ::max()
  123. {
  124.     if(headNode == Null )
  125.     cout<< "\n Undefined Value";
  126.     else
  127.     {
  128.         //declaring the initialize temp
  129.         Node *temp = headNode;
  130.         int mx = temp->get();
  131.         //show content of node
  132.         while(temp !=Null)
  133.         {
  134.             if (mx<temp->get() )
  135.             mx  = temp -> get () ;
  136.             //move into next node
  137.             temp = temp->getNext();
  138.         }
  139.         cout<<"/n The Maximum Element in List is"<<  mx;
  140.     }
  141.     cout<<"/n"
  142. }
  143.  
  144.  
  145.     }       
  146.  
  147.  
  148. /////////////////////      LinkList.h
  149.  
  150.  
  151.  
  152. #include "Node.h"
  153.  
  154. /* The LinkList class declaration*/
  155. class   LinkList 
  156. {
  157. public:
  158.     LinkList();
  159.     void   add (int   addObject);
  160.     int     get();
  161.     bool   next();
  162.  
  163.     friend void  traverse(LinkList list);
  164.     friend LinkList addNodes();
  165.    friend void mean(LinkList list);
  166.    friend void max(LinkList list);
  167.  
  168. private:
  169.     int  size;
  170.     Node *   headNode;
  171.     Node *   currentNode;
  172.     Node *   lastCurrentNode;
  173.  
  174. };
  175.  
  176.  
  177.  
  178. ///////////////////////     main.cpp
  179.  
  180.  
  181.  
  182.  
  183. #include   "LinkList.h"
  184.  
  185. int main()
  186. {
  187.     LinkList list  =  addNodes();
  188.     traverse(list);
  189.     mean(LinkList list)
  190.     max(LinkList list)
  191.  
  192.  
  193.     system("pause");
  194.     return 0;
  195. }
  196.  
  197.  
  198.  
  199. //////////////////////     Node.cpp
  200.  
  201. #include "Node.h"
  202.  
  203. /* The Node class implementation*/
  204.  
  205. int Node:: get() { 
  206.  
  207.     return   object; 
  208.  
  209.     }
  210. void Node:: set(int   object) {
  211.  
  212.     this->object   =   object; 
  213.  
  214.     }
  215.  
  216. Node * Node::getNext() { 
  217.  
  218.     return   nextNode; 
  219.  
  220.     }
  221. void Node:: setNext(Node   * nextNode) { 
  222.  
  223.     this->nextNode   =   nextNode; 
  224.  
  225.     }
  226.  
  227.  
  228. /////////////////////////////Node.h
  229.  
  230. #include   <iostream>
  231. #include   <stdlib.h>
  232. using namespace std;
  233.  
  234. /* The Node class declaration */
  235.  
  236. class   Node 
  237. {
  238.     public:
  239.         int  get();
  240.         void set(int );
  241.         Node * getNext();
  242.         void setNext(Node *);
  243.  
  244.      private:
  245.        int  object;
  246.        Node * nextNode;
  247. };
Oct 21 '07 #1
2 1574
Ganon11
3,652 Recognized Expert Specialist
Nice code. If you would be so kind as to read our Posting Guidelines, especially the section entitled How to Ask a Question, and come back here, we could help you out.
Oct 21 '07 #2
sicarie
4,677 Recognized Expert Moderator Specialist
king imran-

Dude, you have posted four or five times, and nobody has just done your homework for you. This is an official warning. You post again without trying (and don't answer people who ask you what you have done), you will be banned.
Oct 22 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2611
by: Az Tech | last post by:
Hi people, (Sorry for the somewhat long post). I request some of the people on this group who have good experience using object-orientation in the field, to please give some good ideas for topics to include in a course on object-orientation that I'm going to conduct. (I will later summarize all the replies and discussion, for the
7
2394
by: Alan Bashy | last post by:
Please, guys, In need help with this. It is due in the next week. Please, help me to implement the functions in this programm especially the first three constructor. I need them guys. Please, help me. This was inspired by Exercise 7 and Programming Problem 8 in Chapter 3 of our text. I have done Exercise 7 for you: Below you will find the ADT specification for a string of characters. It represents slightly more that a minimal string...
7
3625
by: x muzuo | last post by:
Hi guys, I have got a prob of javascript form validation which just doesnt work with my ASP code. Can any one help me out please. Here is the code: {////<<head> <title>IIBO Submit Page</title> </head> <style type="text/css">
5
2540
by: Sona | last post by:
I understand the problem I'm having but am not sure how to fix it. My code passes two char* to a function which reads in some strings from a file and copies the contents into the two char*s. Now when my function returns, the values stored in the char* are some garbage values (perhaps because I didn't allocate any memory for them).. but even if I allocate memory in the function, on the return of this function I see garbage.. here is my...
3
1965
by: msnews.microsoft.com | last post by:
Hello. I have this code in a project named ProductsHandler: First, a class called ProductsHandler.vb (this particular code is not important in this question, because the class is correct - it implements both IHttpHandler.ProcessRequest and IHttpHandler.IsReusable). Anyway, here it is: --------------------------------------------------------------------------------------- Imports System.Data.SqlClient Imports System.Web Imports...
1
9665
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej and I was wondering if anyone here would be able to give me some tips for young players such as myself, for learning the language. Is this the best Newsgroup for support with JAVA?
7
1906
by: 511475 | last post by:
What is the best checker to use to find these probles with, besides an experienced set of eyes? This probram is to grade the response to input by user. Grades his marks. Thanks <?xml version="1.0" encoding="utf-8" ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head>
22
3285
by: Amali | last post by:
I'm newdie in c programming. this is my first project in programming. I have to write a program for a airline reservation. this is what i have done yet. but when it runs it shows the number of seats as 0 and the flight no. is also repeating. If any can tell why is this please help me. #include<stdio.h> #include<ctype.h> #include<conio.h>
5
2206
by: mohammaditraders | last post by:
Question # 1 Write a program which consists of a class named Student, the class should consists of three data members Name, Ob_marks, Total_marks and two member functions Cal_percentage() which calculate the percentage of the student by the formula (Ob_marks * 100 )/Total_marks and Display() which show all information of the student. The class should also contain the default constructor which initializes all the data member of...
2
1245
by: pargat.singh | last post by:
Hi Everyone: Please help as i need to write some rounding function in C#. i Wrote one but does not give me correct result. Can some one please correct me C# Codes ######################################################################### dblVal = 1234567.89
0
9708
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10589
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10340
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9161
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7625
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6857
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5527
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4302
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3828
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.