I am Leonard K. I am a C++ Homework Expert at cpphomeworkhelp.com. I hold a Masters in Programming from the University of Arkansas, USA. I have been helping students with their homework for the past 9 years. I solve homework related to C++.
Visit cpphomeworkhelp.com or email info@cpphomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with C++ Homework.
The document discusses functions in C programming. It defines what a function is and explains the advantages of using functions, such as avoiding duplicate code and improving reusability. It describes the different parts of a function - declaration, definition, and call. It explains user-defined and standard library functions. It also covers parameter passing techniques (call by value and call by reference), recursion, and dynamic memory allocation using functions like malloc(), calloc(), realloc(), and free().
The document discusses functions in C programming. It focuses on when to declare functions, how to declare them, and different techniques for using them efficiently. The key points are that functions are the building blocks of C, mastering functions is essential, and the chapter provides tips to write better functions and squeeze more efficiency out of existing functions.
The document provides an overview of the C++ programming language. It discusses that C++ was created by Bjarne Stroustrup to provide Simula's facilities for program organization together with C's efficiency and flexibility for systems programming. The document outlines key C++ features like classes, templates, operator overloading, and exceptions. It also covers topics like class definitions, constructors, destructors, streams, and compiling/linking C++ programs.
To assess the quality of PVS-Studio C# diagnostics, we test it on a large number of software projects. Since projects are written by different programmers from different teams and companies, we have to deal with different coding styles, shorthand notations, and simply different language features. In this article, I will give an overview of some of the features offered by the wonderful C# language, as well as the issues that one may run into when writing in this language.
Contains C programming tutorial for beginners with lot of examples explained. This tutorial contains each and every feature of C programming that will help you. C programming tutorial covering basic C Programming examples, data types, functions, loops, arrays, pointers, etc.
power point presentation on object oriented programming functions conceptsbhargavi804095
The document discusses C++ functions. It covers the following key points in 3 sentences:
Standard functions that are included with C++ like math functions are discussed as well as how to define user-defined functions. User-defined functions are defined with a function header, parameters, and body. Functions can share data through parameters, either by value or by reference, and variables can have local or global scope.
Types of C++ functions:
Standard functions
User-defined functions
C++ function structure
Function signature
Function body
Declaring and Implementing C++ functions
The document provides an overview of the C++ programming language. It discusses the history and development of C++, with key points being that C++ was created by Bjarne Stroustrup in 1983 as an extension of C to support object-oriented programming. It then covers some of the main differences between C and C++, uses of C++, advantages and disadvantages, standard libraries, basic C++ structures like data types, variables, operators, functions, arrays, and pointers.
C++ functions presentation by DHEERAJ KATARIADheeraj Kataria
The document discusses C++ functions. It defines what a function is and describes the different types of C++ functions including standard and user-defined functions. It explains the structure of C++ functions including the function header, signature, and body. It provides examples of defining, declaring, implementing and calling functions. It also discusses topics like function parameters, scope of variables, inline functions, and building libraries.
This document discusses C++ functions. It defines a function as a group of statements that is given a name and can be called from within a program. The structure of a C++ function includes a header and body. The header specifies the return type, name, and parameters, while the body contains the code. Functions can use value, reference, and constant reference parameters. Variables within a function can be local or global. Standard library functions are pre-defined in headers like <iostream> and <math.h>. The document provides examples of defining, calling, and using different types of functions and parameters in C++.
Here is the class Book with the requested attributes and member functions:
#include <iostream>
using namespace std;
class Book {
private:
string title;
string author;
string publisher;
float price;
public:
Book() {
title = "No title";
author = "No author";
publisher = "No publisher";
price = 0.0;
}
void display_data() {
cout << "Title: " << title << endl;
cout << "Author: " << author << endl;
cout << "Publisher: " << publisher << endl;
cout << "Price: " << price << endl;
}
The document discusses C++ functions. It explains that functions allow code to be reused by grouping common operations into reusable blocks of code called functions. Functions have three parts: a prototype that declares the function, a definition that implements it, and calls that execute the function. Functions can take parameters as input and return a value. Grouping common code into well-named functions makes a program more organized and maintainable.
The Ring programming language version 1.5.1 book - Part 20 of 180Mahmoud Samir Fayed
This document summarizes key aspects of lists in the Ring programming language. Lists can be created using square brackets or the ":" operator to define list items. The size of a list can be retrieved using len(). Items can be added or deleted from lists using add() or del(). Individual items can be accessed or set using list indexing. Items can be searched for using find() or binarysearch() for sorted lists.
The document discusses functions in C programming. It defines functions as self-contained blocks of code that perform a specific task. Functions make a program modular and easier to debug. There are four main types of functions: functions with no arguments and no return value, functions with no arguments but a return value, functions with arguments but no return value, and functions with both arguments and a return value. Functions are called by their name and can pass data between the calling and called functions using arguments.
This document provides an introduction to the Python programming language. It covers Python's background, syntax, types, operators, control flow, functions, classes, tools, and IDEs. Key points include that Python is a multi-purpose, object-oriented language that is interpreted, strongly and dynamically typed. It focuses on readability and has a huge library of modules. Popular Python IDEs include Emacs, Vim, Komodo, PyCharm, and Eclipse.
The document provides an overview of the C standard library. It includes a table listing common C standard library header files and briefly describing their purpose, such as <stdio.h> for input/output functions and <stdlib.h> for memory allocation and process control. The C standard library contains functions for tasks like string manipulation, mathematics, random numbers, memory management and more. It provides a standard library that is common across C implementations.
Complete a C++ class implementation for a linked-list of sorted (asc.pdfshahidqamar17
Complete a C++ class implementation for a linked-list of sorted (ascending) positive integers.
The class name for this class is LLSortedPosInt and its specification is outlined in the file
LLSortedPosInt.h. The specification is accompained by two other files: (1) a partial
implementation of the class in the file LLSortedPosInt.cpp and (2) a test program called
testLL.cpp. You are to complete the partial implementation of the class by writing code for the
stubbed member functions. You may NOT make any changes to the specification file. You may
develop and test your class implementation either under Visual Studio or linux; however, your
program must be executable under linux, because that is where it will be tested.
Details: Linked lists are useful data structures for storing data records, particularly in situations
where the items are to be kept sorted, the number of records are dynamic (i.e., changing during
the course of the program’s execution) and the maximum number is arbitrary. In this exercise,
you’ll get a chance to complete the implementation of a linked-list specification. In doing so,
you’ll learn not only how to manipulate pointer objects, but also begin to learn how to create a
new and useful data type.
To get started, I have written a simple linked list definition within the header file called
LLSortedPosInt.h. My definition is, of course, not the only way to define a linked list, but it is
suitable for our simple project. Accompanying the definition is a partial implementation in the
source file LLSortedPosInt.cpp. You are to edit this file using the comments in the file and the
instructions below. Altogether, this assignment asks you to implement 13 functions.
To help with testing your functions implementations, I have provided a main program. This main
program is in the source file testLL.cpp. One quick way to repeatedly exercise your function
tests is to write a test file (I called mine testCases.txt) and use input re-direction.
The 13 functions you must add to complete the implementation are as follows:
a. Constructors (4): Classes must have constructors to initialize instances of the objects. The
constructors you will implement for this project are
i. A default constructor
ii. A constructor taking a single int parameter
iii. A constructor which builds a list from an array of integers
iv. A copy constructor
b. Destructor (1): Because the class specification includes a pointer among the attributes, you
will need to implement a destructor to delete (i.e., free or release) any storage allocated in the
constructors or other member functions.
c. Boolean Functions (2): You are to implement two Boolean functions
i. A function isEmpty() which returns true if the associated list contains no data elements,
and returns false otherwise.
ii. A function containsElement(key) which returns true is key is an element in the list and
returns false otherwise.
d. Member Operator Functions (3): When a class has a pointer among its attributes, as
.
The document provides an introduction to the C programming language, including its history and evolution. It discusses key elements of C programs like main functions, libraries, headers, source/header files. It also covers basic C concepts like data types, variables, operators, functions, pointers, arrays, comments and preprocessor directives. Examples of simple C programs are provided to illustrate these concepts.
Struggling with your C++ homework? Don't let complex programming concepts and challenging assignments hold you back. We're here to provide you with the ultimate solution - expert C++ homework help that guarantees your success!
CPP Homework Help is quality-oriented and has invested heavily in quality control. We have put together the best team of CPP professionals combining talent, creativity, and experience. Our experts can handle every CPP homework and ensure the student secures high grades, within their submission deadline. Every homework is plagiarism free and a turn-it-in report is issued at the time of delivery.
Reach out to our team via: -
Website: https://www.cpphomeworkhelp.com/
Email: support@cpphomeworkhelp.com
Call/WhatsApp: +1(315)557–6473
Get help with C++ homework. Now you Don't have to look the other way. here we help you with your all educational needs. We provide university-based homework help that mainly includes United States (USA) university assignment help, Canada university assignment help, United Kingdom (UK) university assignment help, Australia university assignment help, and many more all over the world. Our experts have successfully done this for the past several years. Visit us at https://www.cpphomeworkhelp.com/
I am Frank P. I am a C++ Programming Homework Expert at cpphomeworkhelp.com. I hold a Masters in Programming from Malacca, Malaysia. I have been helping students with their homework for the past 9 years. I solve homework related to C++ Programming .
Visit cpphomeworkhelp.com or email info@cpphomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with C++ Programming Homework.
I am Jeremy P. I am a C++ Programming Homework Expert at cpphomeworkhelp.com. I hold a Masters in Programming from Loughborough University, UK. I have been helping students with their homework for the past 8 years. I solve homework related to C++ Programming .
Visit cpphomeworkhelp.com or email info@cpphomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with C++ Programming Homework.
I am Thanasis F. I am an Online C++ Homework Expert at cpphomeworkhelp.com. I hold a Masters in Programming from Harvard University. I have been helping students with their homework for the past 6 years. I solve homework related to Online C++.
Visit cpphomeworkhelp.com or email info@cpphomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with Online C++ Homework.
I am Irene M. I am a C++ Homework Expert at cpphomeworkhelp.com. I hold a Masters in Programming from from California, USA. I have been helping students with their homework for the past 10 years. I solve homework related to C++.
Visit cpphomeworkhelp.com or email info@cpphomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with C++ Homework.
I am Baddie K. I am a C++ Homework Expert at cpphomeworkhelp.com. I hold a Masters in Programming from The University of Queensland. I have been helping students with their homework for the past 9 years. I solve homework related to C++.
Visit cpphomeworkhelp.com or email info@cpphomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with C++ Homework.
I am Arnold H. I am a C++ Programming Homework Expert at cpphomeworkhelp.com. I hold a Masters in Programming from The University of Sheffield, UK. I have been helping students with their homework for the past 6 years. I solve homework related to C++ Programming.
Visit cpphomeworkhelp.com or email info@cpphomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with C++ Programming Homework.
I am Jayson L. I am a C++ Homework Expert at cpphomeworkhelp.com. I hold a Masters in Programming from The University of Sheffield, UK. I have been helping students with their homework for the past 8 years. I solve homework related to C++.
Visit cpphomeworkhelp.com or email info@cpphomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with C++ Homework.
I am Moffat K. I am a C++ Programming Homework Expert at cpphomeworkhelp.com. I hold a Masters in Programming from London, UK. I have been helping students with their homework for the past 6 years. I solve homework related to C++ Programming.
Visit cpphomeworkhelp.com or email info@cpphomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with C++ Programming Homework.
I am Daniel N. I am a C++ Homework Expert at cpphomeworkhelp.com. I hold a Masters in Programming from the University of Leeds, UK. I have been helping students with their homework for the past 10 years. I solve homework related to C++.
Visit cpphomeworkhelp.com or email info@cpphomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with C++ Homework.
I am Thanasis F. I am a C++ Homework Expert at cpphomeworkhelp.com. I hold a Masters in Programming from Harvard University. I have been helping students with their homework for the past 5 years. I solve homework related to C++.
Visit cpphomeworkhelp.com or email info@cpphomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with C++ Homework.
I am Jeremy P. I am an Online C++ Homework Expert at cpphomeworkhelp.com. I hold a Masters in Programming from Loughborough University, UK. I have been helping students with their homework for the past 9 years. I solve homework related to Online C++.
Visit cpphomeworkhelp.com or email info@cpphomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with Online C++ Homework.
I am Cage T. I am a C++ Homework Expert at cpphomeworkhelp.com. I hold a Masters in Programming from the University of California, USA. I have been helping students with their homework for the past 6 years. I solve homework related to C++.
Visit cpphomeworkhelp.com or email info@cpphomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with C++ Homework.
I am Bianca H. I am a C++ Homework Expert at cpphomeworkhelp.com. I hold a Masters in Programming from, the University of Nottingham, UK. I have been helping students with their homework for the past 7 years. I solve homework related to C++. Visit cpphomeworkhelp.com or email info@cpphomeworkhelp.com. You can also call on +1 678 648 4277 for any assistance with C++ Homework.
This document provides information about C++ classes and objects. It discusses arrays of class objects, static members and variables, const member functions, and string objects. It also includes examples of catching bugs in C++ code snippets and implementing classes for points, polygons, and rectangles.
The document provides instructions for a C++ programming assignment involving functions, pointers, arrays, and calculating pi. It includes 6 problems to solve:
1. Write functions to demonstrate default arguments, constant arguments, and random number generation.
2. Analyze sample code and identify errors in provided code snippets.
3. Write functions to calculate sums of various data types.
4. Use a Monte Carlo simulation to approximate pi by simulating dart throws on a circle and square.
5. Write functions to print, reverse, and transpose arrays.
6. Write functions to operate on strings and pointers.
This document provides sample code and exercises for learning C++. It covers writing "Hello World" programs, calculating basic statistics, finding prime numbers, working with loops, and debugging a factorial program. The exercises are divided into sections like writing different "Hello World" programs, understanding scope, using conditionals and loops, and fixing errors in a factorial function. Students are instructed to complete the exercises by writing code in separate files and submitting their work.
AI Risk Management: ISO/IEC 42001, the EU AI Act, and ISO/IEC 23894PECB
As artificial intelligence continues to evolve, understanding the complexities and regulations regarding AI risk management is more crucial than ever.
Amongst others, the webinar covers:
• ISO/IEC 42001 standard, which provides guidelines for establishing, implementing, maintaining, and continually improving AI management systems within organizations
• insights into the European Union's landmark legislative proposal aimed at regulating AI
• framework and methodologies prescribed by ISO/IEC 23894 for identifying, assessing, and mitigating risks associated with AI systems
Presenters:
Miriama Podskubova - Attorney at Law
Miriama is a seasoned lawyer with over a decade of experience. She specializes in commercial law, focusing on transactions, venture capital investments, IT, digital law, and cybersecurity, areas she was drawn to through her legal practice. Alongside preparing contract and project documentation, she ensures the correct interpretation and application of European legal regulations in these fields. Beyond client projects, she frequently speaks at conferences on cybersecurity, online privacy protection, and the increasingly pertinent topic of AI regulation. As a registered advocate of Slovak bar, certified data privacy professional in the European Union (CIPP/e) and a member of the international association ELA, she helps both tech-focused startups and entrepreneurs, as well as international chains, to properly set up their business operations.
Callum Wright - Founder and Lead Consultant Founder and Lead Consultant
Callum Wright is a seasoned cybersecurity, privacy and AI governance expert. With over a decade of experience, he has dedicated his career to protecting digital assets, ensuring data privacy, and establishing ethical AI governance frameworks. His diverse background includes significant roles in security architecture, AI governance, risk consulting, and privacy management across various industries, thorough testing, and successful implementation, he has consistently delivered exceptional results.
Throughout his career, he has taken on multifaceted roles, from leading technical project management teams to owning solutions that drive operational excellence. His conscientious and proactive approach is unwavering, whether he is working independently or collaboratively within a team. His ability to connect with colleagues on a personal level underscores his commitment to fostering a harmonious and productive workplace environment.
Date: June 26, 2024
Tags: ISO/IEC 42001, Artificial Intelligence, EU AI Act, ISO/IEC 23894
-------------------------------------------------------------------------------
Find out more about ISO training and certification services
Training: ISO/IEC 42001 Artificial Intelligence Management System - EN | PECB
Webinars: https://pecb.com/webinars
Article: https://pecb.com/article
-------------------------------------------------------------------------------
Lecture_Notes_Unit4_Chapter_8_9_10_RDBMS for the students affiliated by alaga...Murugan Solaiyappan
Title: Relational Database Management System Concepts(RDBMS)
Description:
Welcome to the comprehensive guide on Relational Database Management System (RDBMS) concepts, tailored for final year B.Sc. Computer Science students affiliated with Alagappa University. This document covers fundamental principles and advanced topics in RDBMS, offering a structured approach to understanding databases in the context of modern computing. PDF content is prepared from the text book Learn Oracle 8I by JOSE A RAMALHO.
Key Topics Covered:
Main Topic : DATA INTEGRITY, CREATING AND MAINTAINING A TABLE AND INDEX
Sub-Topic :
Data Integrity,Types of Integrity, Integrity Constraints, Primary Key, Foreign key, unique key, self referential integrity,
creating and maintain a table, Modifying a table, alter a table, Deleting a table
Create an Index, Alter Index, Drop Index, Function based index, obtaining information about index, Difference between ROWID and ROWNUM
Target Audience:
Final year B.Sc. Computer Science students at Alagappa University seeking a solid foundation in RDBMS principles for academic and practical applications.
About the Author:
Dr. S. Murugan is Associate Professor at Alagappa Government Arts College, Karaikudi. With 23 years of teaching experience in the field of Computer Science, Dr. S. Murugan has a passion for simplifying complex concepts in database management.
Disclaimer:
This document is intended for educational purposes only. The content presented here reflects the author’s understanding in the field of RDBMS as of 2024.
Feedback and Contact Information:
Your feedback is valuable! For any queries or suggestions, please contact muruganjit@agacollege.in
Split Shifts From Gantt View in the Odoo 17Celine George
Odoo allows users to split long shifts into multiple segments directly from the Gantt view.Each segment retains details of the original shift, such as employee assignment, start time, end time, and specific tasks or descriptions.
How to Store Data on the Odoo 17 WebsiteCeline George
Here we are going to discuss how to store data in Odoo 17 Website.
It includes defining a model with few fields in it. Add demo data into the model using data directory. Also using a controller, pass the values into the template while rendering it and display the values in the website.
How to Show Sample Data in Tree and Kanban View in Odoo 17Celine George
In Odoo 17, sample data serves as a valuable resource for users seeking to familiarize themselves with the functionalities and capabilities of the software prior to integrating their own information. In this slide we are going to discuss about how to show sample data to a tree view and a kanban view.
Views in Odoo - Advanced Views - Pivot View in Odoo 17Celine George
In Odoo, the pivot view is a graphical representation of data that allows users to analyze and summarize large datasets quickly. It's a powerful tool for generating insights from your business data.
The pivot view in Odoo is a valuable tool for analyzing and summarizing large datasets, helping you gain insights into your business operations.
Webinar Innovative assessments for SOcial Emotional SkillsEduSkills OECD
Presentations by Adriano Linzarini and Daniel Catarino da Silva of the OECD Rethinking Assessment of Social and Emotional Skills project from the OECD webinar "Innovations in measuring social and emotional skills and what AI will bring next" on 5 July 2024
Beyond the Advance Presentation for By the Book 9John Rodzvilla
In June 2020, L.L. McKinney, a Black author of young adult novels, began the #publishingpaidme hashtag to create a discussion on how the publishing industry treats Black authors: “what they’re paid. What the marketing is. How the books are treated. How one Black book not reaching its parameters casts a shadow on all Black books and all Black authors, and that’s not the same for our white counterparts.” (Grady 2020) McKinney’s call resulted in an online discussion across 65,000 tweets between authors of all races and the creation of a Google spreadsheet that collected information on over 2,000 titles.
While the conversation was originally meant to discuss the ethical value of book publishing, it became an economic assessment by authors of how publishers treated authors of color and women authors without a full analysis of the data collected. This paper would present the data collected from relevant tweets and the Google database to show not only the range of advances among participating authors split out by their race, gender, sexual orientation and the genre of their work, but also the publishers’ treatment of their titles in terms of deal announcements and pre-pub attention in industry publications. The paper is based on a multi-year project of cleaning and evaluating the collected data to assess what it reveals about the habits and strategies of American publishers in acquiring and promoting titles from a diverse group of authors across the literary, non-fiction, children’s, mystery, romance, and SFF genres.
Ardra Nakshatra (आर्द्रा): Understanding its Effects and RemediesAstro Pathshala
Ardra Nakshatra, the sixth Nakshatra in Vedic astrology, spans from 6°40' to 20° in the Gemini zodiac sign. Governed by Rahu, the north lunar node, Ardra translates to "the moist one" or "the star of sorrow." Symbolized by a teardrop, it represents the transformational power of storms, bringing both destruction and renewal.
About Astro Pathshala
Astro Pathshala is a renowned astrology institute offering comprehensive astrology courses and personalized astrological consultations for over 20 years. Founded by Gurudev Sunil Vashist ji, Astro Pathshala has been a beacon of knowledge and guidance in the field of Vedic astrology. With a team of experienced astrologers, the institute provides in-depth courses that cover various aspects of astrology, including Nakshatras, planetary influences, and remedies. Whether you are a beginner seeking to learn astrology or someone looking for expert astrological advice, Astro Pathshala is dedicated to helping you navigate life's challenges and unlock your full potential through the ancient wisdom of Vedic astrology.
For more information about their courses and consultations, visit Astro Pathshala.
Integrated Marketing Communications (IMC)- Concept, Features, Elements, Role of advertising in IMC
Advertising: Concept, Features, Evolution of Advertising, Active Participants, Benefits of advertising to Business firms and consumers.
Classification of advertising: Geographic, Media, Target audience and Functions.
Principles of Roods Approach!!!!!!!.pptxibtesaam huma
Principles of Rood’s Approach
Treatment technique used in physiotherapy for neurological patients which aids them to recover and improve quality of life
Facilitatory techniques
Inhibitory techniques
The membership Module in the Odoo 17 ERPCeline George
Some business organizations give membership to their customers to ensure the long term relationship with those customers. If the customer is a member of the business then they get special offers and other benefits. The membership module in odoo 17 is helpful to manage everything related to the membership of multiple customers.
Conducting exciting academic research in Computer Science
CPP Assignment Help
1. C++ Assignment Help
For any help regarding CPP Assignment Help
Visit :- https://www.cpphomeworkhelp.com/ ,
Email :- info@cpphomeworkhelp.com or
Call us at :- +1 678 648 4277
2. Problem 1: C++ Linked List Library (cpplist)
Your job is now to refactor your C code from the second assignment and produce a much more
flexible library with similar functionality– and this time in C++. Download the zipped folder provided in
the file cpplist.zip as a basis of your program and take a look at the existing code.
• Write your implementation code in .cpp files in the src/ directory; feel free to add more header
cpphomeworkhelp.com
Problem
files as needed in the include/ directory.
•GRADER INFO.txtis a file for the grader (don’t edit!) containing PROG: cpplist,
LANG: C++
As before: you should submit a zipped folder using the same directory structure as
the provided zip file. We’ve added a section in the Makefile for your convenience: if
you type make zip in the same folder as your project, a zip file containing all of your
code and the required headers will be constructed in the project directory and you
can upload that to the grader.
We are provided a header file describing the interface for the List data structure. Look
in the file list.h
to find the functionality required of the other functions, which you will write.
II Forward declaration of applyIreduce types class
ApplyFunction;
class ReduceFunction;
3. cpphomeworkhelp.com
int value( size t pos ) const;?
• What is a forward declaration?
• Why is there a function int& value( size t pos ); as well as a function
class List {
II ... put whatever private data members you need here II can
also add any private member functions you'd like
public: List();
-List();
size t length() const; int& value( size t
pos );
int value( size t pos ) const; void append( int
value ); void deleteAll( int value );
void insertBefore( int value, int before ); void apply(
const ApplyFunction &interface );
int reduce( const ReduceFunction &interface ) const; void
print() const;
};
II ..etc
Some questions to ask yourself for understanding:
4. cpphomeworkhelp.com
• Why don’t we include the headers apply.h and reduce.h here?
You’llfind those two other header files containing definitions for yourApplyFunctionand
ReduceFunction
classes, shown here:
#include "list.h"
class ReduceFunction { protected:
virtual int function( int x, int y ) const = 0; public:
int reduce( const List &list ) const; virtual int
identity() const = 0; virtual -ReduceFunction() {}
};
II An example ReduceFunction
class SumReduce : public ReduceFunction { int function(
int x, int y ) const;
public: SumReduce() {}
-SumReduce() {}
int identity() const { return 0; }
};
and then in the source code file:
5. cpphomeworkhelp.com
#include "list.h" #include "reduce.h"
II This works fine, but iterating over a list like this is II fairly slow. See
if you can speed it up!
int ReduceFunction::reduce( const List &list ) const { int result =
identity();
for( size t p = 0; p < list.length(); ++p ) { result = function(
result, list.value( p ) );
}
return result;
}
int SumReduce::function( int x, int y ) const { return x + y;
}
Input/Output Format
Not applicable; your library will be compiled into a testing suite, your implemented functions will be
called by the program, and the behavior checked for correctness. For example, here is a potential test:
#include "list.h" int main() {
int N = 5;
II you'll need to write a copy constructor II to be able to do
this (see Lecture 5) auto list = List{};
6. cpphomeworkhelp.com
for( int i = 0; i < N; ++i ) { list.append( i );
}
list.print(); return 0;
}
Upon calling this function, the code outputs
{ 0 -> 1 -> 2 -> 3 -> 4 }
or whatever your formatted output from list.print() is made to look like. You are strongly encour
aged to write your own tests in test.cpp so that you can try out your implementation code before
submitting it to the online grader.
Best Practices
The problem is only worth 500/1000 points when you submit; the rest of the grade will be based
on how well your code follows C++ best practices and object-oriented programming principles.
See a list of those here. The rubric for the other 500 points is as follows.
• +500 points: Code is eminently readable, follows best practices, highly efficient, well
structured, and extensible.
7. cpphomeworkhelp.com
• +400 points: Code is easy to follow, only a few small violations of best practices, and
extensible.
• +300 points: Adecent refactoring effort, no egregiously bad practices, might be difficult to
extend.
• +200 points: Some refactoring effort, lots of violations of best practices, not very
extensible
• +100 points: Minor refactorings/improvements, little effort to follow best practices.
• +0 points: No effort to refactor or improve code (basically direct copy of HW#2)
8. cpphomeworkhelp.com
Look in list.h for a sense of the structure of the solution. The big idea to speed up the
reduce/apply functions while also giving users a nice way to iterate over the items in the list is to
create an "iterator" type within our class. Users will be able to write code similar to the STL:
// Print out every item in the list for( List::iterator it = list.begin(); it != list.end(); ++it ) {
std::cout < < *it << "n"; }
To speed up our "append" function, the List class will also store a pointer to the very last element
in the current list.
Directory structure:
•GRADER_INFO.txt
•include
•apply.h
•list.h
•list_node.h
•reduce.h
•Makefile
•src
•apply.cpp
•list.cpp
•list_iterator.cpp
•list_node.cpp
•reduce.cpp
•test.cpp
Solutions
9. cpphomeworkhelp.com
Here are the contents of apply.h:
#ifndef _6S096_CPPLIST_APPLY_H
#define _6S096_CPPLIST_APPLY_H
#include "list.h" class ApplyFunction {
protected:
virtual int function( int x ) const = 0;
public:
void apply( List &list ) const;
virtual ~ApplyFunction() {}
};
// An example ApplyFunction (see apply.cpp)
class SquareApply : public ApplyFunction { int
function( int x ) const;
};
#endif // _6S096_CPPLIST_APPLY_H
Here are the contents of list.h:
#ifndef _6S096_CPPLIST_H
#define _6S096_CPPLIST_H
10. cpphomeworkhelp.com
#include <cstddef>
#include <stdexcept>
class ApplyFunction;
class ReduceFunction;
class ListNode;
class List
{ size_t _length;
ListNode *_begin;
ListNode *_back;
public: // Can use outside as List::iterator type
class iterator { // Making List a friend class means we'll be able to access
// the private _node pointer data within the scope of List.
friend class List;
ListNode *_node;
public:
iterator( ListNode *theNode );
iterator& operator++();
int& operator*();
11. cpphomeworkhelp.com
#include <cstddef>
#include <stdexcept>
class ApplyFunction;
class ReduceFunction;
class ListNode;
bool operator==( const iterator &rhs );
bool operator!=( const iterator &rhs ); }; //
Can use outside as List::const_iterator type
class const_iterator {
// Again, this is basically the only situation you should
// be using the keyword 'friend'
friend class List;
ListNode *_node;
public:
const_iterator( ListNode *theNode );
const_iterator& operator++();
const int& operator*(); bool operator==( const const_iterator &rhs );
bool operator!=( const const_iterator &rhs );
};
List(); List( const List &list );
List& operator=( const List &list )
; ~List(); size_t length()const; int& value( size_t pos )
12. cpphomeworkhelp.com
; int value( size_t pos ) const;
bool empty() const;
iterator begin();
const_iterator begin() const;
iterator back();
const;
iterator back();
const_iterator back()
const; iterator end();
const_iterator end()
const;
iterator find( iterator s, iterator t, int needle );
void append( int theValue );
void deleteAll( int theValue );
void insertBefore( int theValue, int before );
void insert( iterator pos, int theValue );
void apply( const ApplyFunction &interface );
int reduce( const ReduceFunction &interface ) const;
void print() const;
void clear();
private: ListNode* node( iterator it ) { return it._node;
}
ListNode* node( const_iterator it ) { return it._node;
} };
class ListOutOfBounds :
13. cpphomeworkhelp.com
#ifndef _6S096_CPPLIST_NODE_H
#define _6S096_CPPLIST_NODE_H
class ListNode
{ int _value; ListNode *_next;
ListNode( const ListNode & ) = delete;
ListNode& operator=( const ListNode & ) = delete;
public:
ListNode();
ListNode( int theValue );
~ListNode();
int& value();
int value() const; ListNode* next();
void insertAfter( ListNode *before );
void setNext( ListNode *nextNode );
static void deleteNext( ListNode *before );
static void deleteSection( ListNode *before,
ListNode *after );
static ListNode* create( int theValue = 0 ); };
public std::range_error
{
public:
explicit ListOutOfBounds() : std::range_error( "List
index out of bounds" ) {} };
#endif // _6S096_CPPLIST_H
Here are the contents of list_node.h:
14. cpphomeworkhelp.com
#endif // _6S096_CPPLIST_NODE_H
Here are the contents of reduce.h:
#ifndef _6S096_CPPLIST_REDUCE_H
#define _6S096_CPPLIST_REDUCE_H
#include "list.h"
class ReduceFunction {
protected:
virtual int function( int x, int y ) const = 0;
public:
int reduce( const List &list )
const; virtual int identity() const = 0;
virtual ~ReduceFunction() {} };
// An example ReduceFunction
class SumReduce :
public ReduceFunction
{ int function( int x, int y ) const;
public:
SumReduce()
{} ~SumReduce() {}
int identity() const { return 0; } }; // Another ReduceFunction
class ProductReduce :
public ReduceFunction { int function( int x, int y )
const;
public:
ProductReduce() {}
~ProductReduce() {}
15. cpphomeworkhelp.com
iint identity() const { return 1; } };
#endif // _6S096_CPPLIST_REDUCE_H
Here is the source code file apply.cpp:
#include "list.h" #include "apply.h"
void
ApplyFunction::apply( List &list )
const
{ for( auto it = list.begin(); it != list.end(); ++it ) {
*it = function( *it );
}
}
int SquareApply::function( int x ) const {
return x * x; }
Here is the source code file list.cpp:
#include "list.h"
#include "list_node.h"
#include "apply.h"
#include "reduce.h"
#include <iostream>
List::List() : _length{0}, _begin{
nullptr }, _back{ nullptr } {}
List::List(
const List &list ) : _length{0}, _begin{nullptr}, _back{
16. cpphomeworkhelp.com
nullptr} {
for( auto it = list.begin(); it != list.end(); ++it )
{ append( *it );
}
}
List& List::operator=( const List &list ) {
if( this != &list ) { clear();
for( auto it = list.begin(); it != list.end(); ++it ) { append( *it ); } }
return *this;
} List::~List() { clear(); }
} } return *this; }
List::~List() { clear(); } size_t List::length() const {
return _length; } int& List::value( size_t pos ) { auto it = begin();
for( size_t i = 0; i < pos && it != end(); ++it, ++i );
if( it == end() ) {
throw ListOutOfBounds(); }
return *it; } int List::value( size_t pos )
const { auto it = begin();
for( size_t i = 0; i < pos && it != end(); ++it, ++i );
if( it == end() ) {
Throw
void List::append( int theValue )
{ auto *newNode = ListNode::create( theValue );
if( empty() ) {
17. cpphomeworkhelp.com
newNode->setNext( _back );
_begin = newNode;
} else
{ newNode->insertAfter( _back );
}
_back = newNode;
++_length;
}
void List::deleteAll( int theValue ) {
if( !empty() ) {
// Delete from the front
while( _begin->value() == theValue && _begin != _back ) {
auto *newBegin = _begin->next(); delete _begin; _begin =
newBegin; --_
length; }
auto *p = _begin;
if( _begin != _back ) {
// Normal deletion from interior of list
for( ; p->next() != _back; )
{ if( p->next()->value() == theValue )
{ ListNode::deleteNext( p ); --
_length; } else {
p = p->next();
}
}
18. cpphomeworkhelp.com
// Deleting the last item
if( _back->value() == theValue ) {
ListNode::deleteNext( p ); _
back = p;
--_length; }
} else if( _begin->value() == theValue )
{
// Deal with the case where we deleted the whole list _
begin = _back = nullptr; _
length = 0;
}
}
}
List::iterator List::find( iterator s, iterator t, int needle ) {
for( auto it = s; it != t; ++it ) {
if( *it == needle )
{ return it;
}
} return t; }
void List::insert( iterator pos, int theValue ) {
auto *posPtr = node( pos );
auto *newNode = ListNode::create( theValue );
newNode->insertAfter( posPtr ); ++_length; }
void List::insertBefore( int theValue, int before ) {
if( !empty() ) {
19. cpphomeworkhelp.com
if( _begin->value() == before )
{ auto *newNode = ListNode::create(
theValue );
newNode->setNext( _begin ); _begin =
newNode;
++_length; }
else { auto *p = _begin;
for( ; p != _back && p->next()->value() !=
before; p = p->next() );
if( p != _back && p->next()->value() ==
before ) {
auto *newNode = ListNode::create( theValue );
newNode->insertAfter( p );
++_length;
}
}
}
}
void List::apply(
const ApplyFunction &interface ) {
interface.apply( *this ); } int List::reduce(
const ReduceFunction &interface ) const {
return interface.reduce( *this ); }
void List::print()
21. cpphomeworkhelp.com
const const_iterator &rhs ) {
return _node != rhs._node;
}
Here is the source code file list_node.cpp:
#include "list_node.h"
ListNode::ListNode() :
_value{0}, _next{nullptr} {} ListNode::ListNode( int theValue ) :
_value{theValue}, _next{nullptr} {} ListNode::~ListNode() {} int&
ListNode::value() { return _value; } int ListNode::value(){const { return _value;
} ListNode* ListNode::next() { return _next; } void ListNode::insertAfter(
ListNode *before ) { _next = before->next(); before->_next = this;
}
void ListNode::setNext( ListNode *nextNode ) { _next = nextNode; } void
ListNode::deleteNext( ListNode *before ) { auto *after = before->next()->next();
delete before->next(); before->_next = after; } void ListNode::deleteSection(
ListNode *before, ListNode *after ) { auto *deleteFront = before->next(); while(
deleteFront != after ) { auto *nextDelete = deleteFront->next(); delete deleteFront;
deleteFront = nextDelete; } } ListNode* ListNode::create( int theValue ) { return
new ListNode{ theValue }; }
Here is the source code file reduce.cpp:
#include "list.h" #include "reduce.h" int ReduceFunction::reduce(const List &list )
const { int result = identity(); for( auto it = list.begin(); it != list.end(); ++it ) {
result = function( result, *it ); } return result; }
22. cpphomeworkhelp.com
int SumReduce::function( int x, int y ) const { return x + y; }
int ProductReduce::function(int x, int y ) const { return x * y; }
Below is the output using the test data:
cpplist: 1: OK [0.004 seconds] OK!
2: OK [0.005 seconds] OK!
3: OK [0.005 seconds] OK!
4: OK [0.009 seconds] OK!
5: OK [0.006 seconds] OK!
6: OK [0.308 seconds] OK!
7: OK [0.053 seconds] OK!
8: OK [0.007 seconds] OK!
9: OK [0.005 seconds] OK!
10: OK [0.742 seconds] OK!