0% found this document useful (0 votes)
23 views4 pages

S24 PF AFour Part Two

Uploaded by

tamamsolutions4
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views4 pages

S24 PF AFour Part Two

Uploaded by

tamamsolutions4
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Programming Fundamentals

Session: Spring 2024


COPY WILL RESULT IN ZERO MARKS FOR ALL INVOLVED
EVEN A COPY OF A SINGLE CODE RESULTS IN ZERO MARKS IN
THE WHOLE ASSIGNMENT
CHATGPT USE RESULTS IN ZERO MARKS
NOT OWN WORK ZERO MARKS (CAN’T EXPLAIN)
THE CODE MUST COMPILE AND RUN TO BE GRADED
THIS SECOND PART IS DUE ON PORTAL ONLY

Assignment no Four Part Two: Coding


Due .cpp File ON PORTAL ONLY
Deadline: Mon July 01, 2024
Marks of EACH SET are Shown
EACH FUNCTION IS OF 5 MARSK UNLESS MENTIONED OTEHRWISE
YOU GET AS MANY MARKS AS MANY FUNCTION YOU SUBMIT BY
THE DEADLINE
THEREFORE, NO EXTENSION WILL BE GIVEN IN THE DEADLINE
Functions, Pointers, 2D Arrays and 2D Dynamic arrays (Coding Practice)
Topic

Objective/ • Using Pointers as Variables and as the Head of Dynamic Arrays


Outcome • 2D Arrays and Double Pointers
• Solving Complex Coding Problems
• Writing Code to Solve Gradually Simple to Complex Problems

Problem statement:
• In this PART of Assignment 4, you write and test simple to moderately complex
functions
• You will use only Dynamic Arrays of Exact Size and Avoid Memory Leaks
• You May Use local Fixed Size Arrays inside functions but NOT IN MAIN
SUBMISSION INSTRUCTIONS:
You will need to do 2 main submission for the whole Assignment:

(NOT FOLLIWNG FOLLOWING INSTRUCTIONS MAY REDUCE YOUR


MARKS SIGNIFICANTLY)
1. A single ZIP File containing all the code files, one per each function. Therefore, in this ZIP file,
you will have as many .cpp files as many functions you have written and tested. Use the
following naming convention for this zip file: “S14_PF_Secion_B1_REGNO_A4.zip” e.g. for a
registration number of L1S23BSCS0111 the file name must be “S14_PF_Secion_B24_
L1S23BSCS0111 _A4.zip”
2. A single docx File that contains screenshots of all the test run of the functions you have
submitted. You must label each screenshot with the Set and Function. The name of file must be
“S14_PF_Secion_B24_REGNO_A4.docx”

For the following description of each function of the set of function, you will do the following (must
reuse code where possible):

1. Use the Exact Function name and Function Prototype given


2. Write Code of a main function that tests the function
3. Write Code of the Function
4. Compile and Run the Program
5. Save the Screen shot in a doc File

SET ONE: WRITING FUNCTIONS AND TESTING IN A MAIN FUNCTION


Learning Objectives
• Use of Pointers, Dynamic Variables and 1D Dynamic Arrays

Functions to Write:
1. create: that creates a float 1D Dynamic Array of Given Size and then returns the newly created
array
float * create(int);
2. allocate: that allocates memory to a float pointer equal to provided Size and then returns the
newly allocated pointer
void allocate(float * &, int);
3. read: that reads as many decimal values from the user as the user wants. So first ask the user for
amount of decimals to enter and then read that many decimals in a dynamic array of exact size
as the amount. [10 marks]
float * read(int &);
4. grow: that grows a float 1D Dynamic by a given amount
float * grow(int &, int);
5. shrink: that shrinks a float 1D Dynamic by a given amount
void shrink (float & *, int &, int);
6. autoGrow: that automatically grows a float 1D Dynamic by a given amount if the array contains
values up to some percent of the capacity of the array. For example if an array capacity is 10
values and the array is filled up to 70 percent (or has 7 values) the array should auto-grow
void autoGrow(float & *, int &, int, int);
7. autoShrink: that automatically shrinks a float 1D Dynamic by a given amount if the array
contains values up to some percent of the capacity of the array. For example if an array capacity
is 10 values and the array has 50 percent(or has) values, then the array should auto-shrink by
the given amount
float * autoShrink(int &, int, int);
8. addValue: add a given float value at a desired index to a float 1D Dynamic of a given size and
capacity (all the values after the index must shift right). If the size reaches a percent capacity
the array is auto-grown by a given amount. [10 marks]
float * addValue (float, int, int &, int);
9. deleteValue: deletes a float value at a given index from a float 1D Dynamic of a given size and
capacity (all the values after the index must shift left). If the size reaches a percent capacity the
array is auto-shrunk by a given amount. [10 marks]
void deleteValue (float * &, int, int &, int);
10. readFromFile: that reads integers values, in a dynamic array, from a text file provided by the
user. Initially the 1D Dynamic Arrays will be equal to nullptr and will grow as the values are read
from the file one by one
float * readFromFile(int &);

SET TWO: WRITING FUNCTIONS FOR CSTRING MANUPULATION,


TESTING IN A MAIN FUNCTIONS
Learning Objectives

• Use of Pointers, Dynamic Variables and 1D Dynamic Arrays to Solve Complex Problems

Functions to Write: (You may need to write own other functions to distribute amount of work)
1. insert: that inserts a given CString in an existing CSTring at a given index
void insert(char *, char *, int);
2. find: that finds a given word in a CSTring and if found returns the index of the word, otherwise
return -1
int find(char *, char *);
3. read: that reads an English Paragraph from a text file, in a (CString) 1D character Array (don’t
use getc or any of the single character reading functions) [10 marks]
char * read(int&);
4. replace: that replaces a given word, if found, with another word in a CString containing English
words (don’t use getc or any of the single character reading functions). If word is found and
replacement is successful then return the index of the word otherwise return -1
int replace(char *, char *, char *); [10 marks]
5. parse: that parses a given CString for an English word present between 2 special characters, if
the word is found then return that word and its index (by reference).
char * parse(char *, char *, int &, char, char); [20 marks]
SET THREE: WRITING FUNCTIONS FOR 2D DYNAMIC ARRAYS, TESTING
IN A MAIN FUNCTIONS
Learning Objectives

• Use of DOUBLE Pointers, Dynamic Variables and 2D Dynamic Arrays to Solve Complex Problems

Functions to Write: (You may need to write own other functions to distribute amount of work)
1. grow: that grows in both dimension, a given 2D float Dynamic array
float ** grow(float **, int &, int &, int, int); [10 marks]
2. read: that reads a m x n float matrix, from a text file “matrix.txt”, in a 2D Character Array
(initially set to nullptr with zero rows and zero columns) [10 marks]
sample File matrix.txt (comma indicates end of a row) [3 x 4 matrix)
1.1 1.2 1.3 1.4,
2.1 2.2 2.3 2.4,
3.1 3.2 3.3 3.4,
3. multiply: that multiplies 2 float matrices A (n x m) & B (m x n) and returns the result in a 3rd float
matrix C (n x n)
float ** multiply(float **, float **, int, int);
4. grow: that grows a given 2D charcater Dynamic array (or 1D Dynamic array of CStrings if exact
sizes)
void grow(char ** &, int &, int);
5. read: that reads an English Paragraph in a 2D Character Array (or 1D array of CStrings), from a
text file [10 marks]
char ** read(int &);

You might also like