The document provides examples of C++ functions that accept integer arrays as arguments and rearrange or modify the elements in various ways. One function converts a 1D array into a 2D array by assigning elements to rows and columns. Another replaces even elements with half their value and odd elements with double their value. A third swaps elements of even and odd indices. The examples demonstrate functions that rearrange arrays in reverse order or sort structures by a field using bubble sort.
N-Queens Combinatorial Problem - Polyglot FP for fun and profit - Haskell and...Philip Schwarz
Learn how to write FP code that displays a graphical representation of all the numerous N-Queens solutions for N=4,5,6,7,8 .
See how to neatly solve the problem by exploiting its self-similarity and using a divide and conquer approach.
Make light work of assembling multiple images into a whole, by exploiting Doodle’s facilities for combining images using a relative layout.
See relevant FP functions, like Foldable’s intercalate and intersperse, in action.
Code for part 3: https://github.com/philipschwarz/n-queens-combinatorial-problem-scala-part-3
Download for flawless quality (slides viewed online look a bit grainy and out of focus).
Equivalence of nested flatMaps and chained flatMaps for Kleisli arrow composition.
N-Queens Combinatorial Problem - Polyglot FP for fun and profit - Haskell and...Philip Schwarz
Learn how to write FP code that displays a graphical representation of all the numerous N-Queens solutions for N=4,5,6,7,8 .
See how to neatly solve the problem by exploiting its self-similarity and using a divide and conquer approach.
Make light work of assembling multiple images into a whole, by exploiting Doodle’s facilities for combining images using a relative layout.
See relevant FP functions, like Foldable’s intercalate and intersperse, in action.
Code for part 3: https://github.com/philipschwarz/n-queens-combinatorial-problem-scala-part-3
Download for flawless quality (slides viewed online look a bit grainy and out of focus).
Equivalence of nested flatMaps and chained flatMaps for Kleisli arrow composition.
Very quick introduction to the language R. It talks about basic data structures, data manipulation steps, plots, control structures etc. Enough material to get you started in R.
COURSE TITLE: SOFTWARE DEVELOPMENT VI
COURSE CODE: VIT 351
TOPICS COVERED:
ARRAYS
TYPES OF ARRAYS
MULTIDIMENSIONAL ARRAYS
CHARACTER HANDLING IN C
STRING HANDLING IN C
QUIZ SET 2
This file contains all the practicals with output regarding GTU syllabus. so it will help to IT and Computer engineering students. It is really knowledgeable so refer these for computer graphics practicals.
Very quick introduction to the language R. It talks about basic data structures, data manipulation steps, plots, control structures etc. Enough material to get you started in R.
COURSE TITLE: SOFTWARE DEVELOPMENT VI
COURSE CODE: VIT 351
TOPICS COVERED:
ARRAYS
TYPES OF ARRAYS
MULTIDIMENSIONAL ARRAYS
CHARACTER HANDLING IN C
STRING HANDLING IN C
QUIZ SET 2
This file contains all the practicals with output regarding GTU syllabus. so it will help to IT and Computer engineering students. It is really knowledgeable so refer these for computer graphics practicals.
c++ program I need to sort arrays using an insertion sort and a mer.pdfdhavalbl38
c++ program: I need to sort arrays using an insertion sort and a merge sort (I already have). I
need to use these sorting methods to sort input arrays in the form of randomly generated numbers
in the size of 20, 100 and 200. So I need 3 randomily generated arrays and sorted and outputed
by both sorting method. I currently have it as given arrays and need help changing them to
randomily generated arrays
Here is my code so far:
#include
using namespace std;
void InsertionSort(int arr[],int size){
int temp,j;
for(int i=0; i=0){
arr[j+1] = arr[j];
j--;
}
arr[j+1] = temp;
}
}
//Merges two sub-arrays. First sub-array is arr[l..m],second is arr[m+1..r]
void merge(int arr[], int l, int m, int r){
int i, j, k;
int n1 = m - l + 1;
int n2 = r - m;
//Create temp arrays
int L[n1], R[n2];
//Copy data to temp arrays L[] and R[]
for (i = 0; i < n1; i++)
L[i] = arr[l + i];
for (j = 0; j < n2; j++)
R[j] = arr[m + 1+ j];
/* Merge arrays back into arr[l..r]*/
i = 0;
j = 0;
k = l;
while (i < n1 && j < n2){
if (L[i] <= R[j]){
arr[k] = L[i];
i++;
}
else{
arr[k] = R[j];
j++;
}
k++;
}
//Copy the remaining elements of L[], if there are any
while (i < n1){
arr[k] = L[i];
i++;
k++;
}
//Copy the remaining elements of R[], if there are any
while (j < n2){
arr[k] = R[j];
j++;
k++;
}
}
//l is left index and r is right index of the sub-array of array to be sorted
void MergeSort(int arr[], int l, int r){
if (l < r){
// Same as (l+r)/2, but avoids overflow for large l and h
int m = l+(r-l)/2;
// Sort first and second halves
MergeSort(arr, l, m);
MergeSort(arr, m+1, r);
merge(arr, l, m, r);
}
}
void printArray(int arr[], int size){//Function to print array
int i;
for (i=0; i < size; i++)
cout << arr[i] <<\" \";
cout << endl;
}
int main(){
int size = 20;
int array1[] = {17,33,88,54,96,82,12,36,69,74,79,66,32,11,1,98,76,55,3,4};
int array2[] = {20,1,19,2,18,3,17,4,16,5,15,6,14,7,13,8,12,9,11,10};
int array3[] = {220,209,198,187,176,165,154,143,132,121,110,99,88,77,66,55,44,33,22,11};
int array4[] = {15,35,85,100,40,90,70,65,25,5,10,30,55,75,80,95,20,45,50,60};
int array5[] = {100,99,98,97,96,95,94,93,92,91,90,89,88,87,86,85,84,83,82,81};
//Output for array1
cout << \"Original array 1: \ \";
printArray(array1, size);
InsertionSort(array1, size);
cout << \"Array 1 sorted by INSERTION SORT: \ \";
printArray(array1, size);
cout << \"\ \";
//Output for array2
cout << \"Original array 2: \ \";
printArray(array2, size);
MergeSort(array2,0,size);
cout << \"Array 2 sorted by MERGE SORT: \ \";
printArray(array2, size);
cout << \"\ \";
//Output for array3
cout << \"Original array 3: \ \";
printArray(array3, size);
InsertionSort(array3, size);
cout << \"Array 3 sorted by INSERTION SORT: \ \";
printArray(array3, size);
cout << \"\ \";
//Output for array4
cout << \"Original array 4: \ \";
printArray(array4, size);
MergeSort(array4,0,size);
cout << \"Array 4 sorted by MERGE SORT: \ \";
printArray(array4, size);
cout << \"\ \";
//Output for array5
cout << \"Original array 5: \ \";
printArray(arr.
1sequences and sampling. Suppose we went to sample the x-axis from X.pdfrushabhshah600
1sequences and sampling. Suppose we went to sample the x-axis from Xmin to Xmax using a
step size of step
A)Draw a picture of what is going on.
B) Write a expression for n the total number of samples involved (in terms of Xmin, Xmax and
step)
C) Write out the sequence of x-samples
D) Write a direct and general expression for xi that captures the sequence
E) Write a recursive expression for the sequence
F) Write a program to compute and store the x-samples over the range -5x5 using a step size of
0.1 do everything in main ()
2 . We talked about the following string functions that are available in C (as long as you include
string.h):
int strlen(char str[])
void strcpy(char str1[], char str2[])
void strcat(char str1[], str2[])
Write your own versions of these functions; for example: int paul_strlen(int char str[]). Hint: for
your version of the strlen function, start at the first character in the array and keep counting until
you find the ‘\\0’ character (use a while loop for this). Note: Use your version of the strlen
function in the strcpy and strcat functions.
9. We want to insert a number into an array.
(a) Formulate the problem mathematically with two sequences: x and y. (b) Write a function of
the form:
insertNumIntoArray(int n, int array[], int num, int index)
The function inserts num into the array at the specified index. The rest of the array then follows.
For example, if num = 9 and index = 3 and array = [7 2 8 8 3 1 2] then the function will produce:
array = [7 2 8 9 8 3 1 2]
Note: assume that array is properly dimensioned to have at least 1 extra space for storage.
10. Repeat #2 by for the delete operation; that is, we want to delete a single element (at a
specified index) from an array; for example, suppose index = 3 and array = [50 70 10 90 60 20],
then the result will be
array: [50 70 10 60 20]
11. Repeat #2 by for an insert operation where we are inserting several values into the array. The
function should be of the form:
int insertArrayIntoArray(int n, int inArray[],
int nInsert, int insertArray[], int outArray[], int index)
The dimension of outArray is returned (explicitly). For example:
inArrayarray: [7 2 8 6 3 9]
insertArray: [50 60 70]
index: 2
outArray: [7 2 50 60 70 8 6 3 9]
Assume that outArray is large enough to hold all n + nInsert values.
Solution
#include
//Simulates strlen() library function
int paul_strlen(char str[])
{
int l;
for(l = 0; str[l] != \'\\0\'; l++) ;
return l;
}
//Simulates strcpy() library function
void paul_strcpy(char str1[], char str2[])
{
int c;
for(c = 0; str1[c] != \'\\0\'; c++)
str2[c] = str1[c];
str2[c] = \'\\0\';
printf(\"\ Original String: %s\", str1);
printf(\"\ Copied String: %s\", str2);
}
//Simulates strcat() library function
void paul_strcat(char str1[], char str2[])
{
int i, j;
for(i = 0; str1[i] != \'\\0\'; i++) ;
for (j = 0; str2[j] != \'\\0\'; i++, j++)
{
str1[i] = str2[j];
}
str1[i] = \'\\0\';
printf(\"\ Concatenated String: %s\", str1);
}
int main()
{
char data1[20], data2[20];
pri.
computer dataA computer is a machine that can be programmed to carry out sequences of arithmetic or logical operations (computation) automatically. Modern digital electronic computers can perform generic sets of operations known as programs. These programs enable computers to perform a wide range of tasks. A computer system is a nominally complete computer that includes the hardware, operating system (main software), and peripheral equipment needed and used for full operation. This term may also refer to a group of computers that are linked and function together, such as a computer network or computer cluster.
A broad range of industrial and consumer products use computers as control systems. Simple special-purpose devices like microwave ovens and remote controls are included, as are factory devices like industrial robots and computer-aided design, as well as general-purpose devices like personal computers and mobile devices like smartphones. Computers power the Internet, which links billions of other computers and users.
Early computers were meant to be used only for calculations. Simple manual instruments like the abacus have aided people in doing calculations since ancient times. Early in the Industrial Revolution, some mechanical devices were built to automate long, tedious tasks, such as guiding patterns for looms. More sophisticated electrical machines did specialized analog calculations in the early 20th century. The first digital electronic calculating machines were developed during World War II. The first semiconductor transistors in the late 1940s were followed by the silicon-based MOSFET (MOS transistor) and monolithic integrated circuit chip technologies in the late 1950s, leading to the microprocessor and the microcomputer revolution in the 1970s. The speed, power and versatility of computers have been increasing dramatically ever since then, with transistor counts increasing at a rapid pace (as predicted by Moore's law), leading to the Digital Revolution during the late 20th to early 21st centuries.
These program are helpful for the beginners who are learning swift .It is helpful for BCA,MCA and B.Tech student for learning the array programs in swift
Biological screening of herbal drugs: Introduction and Need for
Phyto-Pharmacological Screening, New Strategies for evaluating
Natural Products, In vitro evaluation techniques for Antioxidants, Antimicrobial and Anticancer drugs. In vivo evaluation techniques
for Anti-inflammatory, Antiulcer, Anticancer, Wound healing, Antidiabetic, Hepatoprotective, Cardio protective, Diuretics and
Antifertility, Toxicity studies as per OECD guidelines
Embracing GenAI - A Strategic ImperativePeter Windle
Artificial Intelligence (AI) technologies such as Generative AI, Image Generators and Large Language Models have had a dramatic impact on teaching, learning and assessment over the past 18 months. The most immediate threat AI posed was to Academic Integrity with Higher Education Institutes (HEIs) focusing their efforts on combating the use of GenAI in assessment. Guidelines were developed for staff and students, policies put in place too. Innovative educators have forged paths in the use of Generative AI for teaching, learning and assessments leading to pockets of transformation springing up across HEIs, often with little or no top-down guidance, support or direction.
This Gasta posits a strategic approach to integrating AI into HEIs to prepare staff, students and the curriculum for an evolving world and workplace. We will highlight the advantages of working with these technologies beyond the realm of teaching, learning and assessment by considering prompt engineering skills, industry impact, curriculum changes, and the need for staff upskilling. In contrast, not engaging strategically with Generative AI poses risks, including falling behind peers, missed opportunities and failing to ensure our graduates remain employable. The rapid evolution of AI technologies necessitates a proactive and strategic approach if we are to remain relevant.
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdfTechSoup
In this webinar you will learn how your organization can access TechSoup's wide variety of product discount and donation programs. From hardware to software, we'll give you a tour of the tools available to help your nonprofit with productivity, collaboration, financial management, donor tracking, security, and more.
Francesca Gottschalk - How can education support child empowerment.pptxEduSkills OECD
Francesca Gottschalk from the OECD’s Centre for Educational Research and Innovation presents at the Ask an Expert Webinar: How can education support child empowerment?
Instructions for Submissions thorugh G- Classroom.pptxJheel Barad
This presentation provides a briefing on how to upload submissions and documents in Google Classroom. It was prepared as part of an orientation for new Sainik School in-service teacher trainees. As a training officer, my goal is to ensure that you are comfortable and proficient with this essential tool for managing assignments and fostering student engagement.
Introduction to AI for Nonprofits with Tapp NetworkTechSoup
Dive into the world of AI! Experts Jon Hill and Tareq Monaur will guide you through AI's role in enhancing nonprofit websites and basic marketing strategies, making it easy to understand and apply.
Synthetic Fiber Construction in lab .pptxPavel ( NSTU)
Synthetic fiber production is a fascinating and complex field that blends chemistry, engineering, and environmental science. By understanding these aspects, students can gain a comprehensive view of synthetic fiber production, its impact on society and the environment, and the potential for future innovations. Synthetic fibers play a crucial role in modern society, impacting various aspects of daily life, industry, and the environment. ynthetic fibers are integral to modern life, offering a range of benefits from cost-effectiveness and versatility to innovative applications and performance characteristics. While they pose environmental challenges, ongoing research and development aim to create more sustainable and eco-friendly alternatives. Understanding the importance of synthetic fibers helps in appreciating their role in the economy, industry, and daily life, while also emphasizing the need for sustainable practices and innovation.
Macroeconomics- Movie Location
This will be used as part of your Personal Professional Portfolio once graded.
Objective:
Prepare a presentation or a paper using research, basic comparative analysis, data organization and application of economic information. You will make an informed assessment of an economic climate outside of the United States to accomplish an entertainment industry objective.
Acetabularia Information For Class 9 .docxvaibhavrinwa19
Acetabularia acetabulum is a single-celled green alga that in its vegetative state is morphologically differentiated into a basal rhizoid and an axially elongated stalk, which bears whorls of branching hairs. The single diploid nucleus resides in the rhizoid.
Unit 8 - Information and Communication Technology (Paper I).pdfThiyagu K
This slides describes the basic concepts of ICT, basics of Email, Emerging Technology and Digital Initiatives in Education. This presentations aligns with the UGC Paper I syllabus.
Operation “Blue Star” is the only event in the history of Independent India where the state went into war with its own people. Even after about 40 years it is not clear if it was culmination of states anger over people of the region, a political game of power or start of dictatorial chapter in the democratic setup.
The people of Punjab felt alienated from main stream due to denial of their just demands during a long democratic struggle since independence. As it happen all over the word, it led to militant struggle with great loss of lives of military, police and civilian personnel. Killing of Indira Gandhi and massacre of innocent Sikhs in Delhi and other India cities was also associated with this movement.
2. (a) Write a function in C++ which accepts an integer
array and its size as arguments / parameters and
assign the elements into a two dimensional array of
integers in the following format D 2006 3
If the array is 1, 2, 3, 4, 5, 6
The resultant 2 D array is given
1 2 3 4 5 6
1 2 3 4 5 0
1 2 3 4 0 0
1 2 3 0 0 0
1 2 0 0 0 0
1 0 0 0 0 0
If the array is 1, 2, 3
The resultant 2 D array is
given below
1 2 3
1 2 0
1 0 0
3. (a) const int R = 100, C = 100;
void Arrayconvert(int A1D[], int N)
{
int A2D[R][C]={0};
for(int I = 0; I<N; I++)
for (int J = 0; J <N-I; J++)
A2D[I][J] = A1D[J];
}
OR
4. (a)
const int R = 100, C = 100;
void Arrayconvert(int A1D[], int N)
{
int A2D[R][C];
for(int I = 0; I<N; I++)
for (int J = 0; J <N; J++)
if (J<N-I)
A2D[I][J] = A1D[J];
else
A2D[I][J] = 0;
}
OR
5. OR
const int R = 100, C = 100;
void Arrayconvert(int A1D[], int N)
{
int A2D[R][C], I, J;
for(I = 0; I<N; I++)
for (J = 0; J <N; J++)
A2D[I][J] = 0;
for(I = 0; I<N; I++)
for (J = 0; J <N-I; J++)
A2D[I][J] = A1D[J];
}
OR
6.
7. 3. (a) Write a function in C++ which accepts
an integer array and its size as arguments/
parameters and assign the elements into a
two dimensional array of integers in the
following format : OD 2006 3
If the array is 1, 2, 3, 4, 5, 6
The resultant 2 D array is given below
1 0 0 0 0 0
1 2 0 0 0 0
1 2 3 0 0 0
1 2 3 4 0 0
1 2 3 4 5 0
1 2 3 4 5 6
If the array is 1, 2, 3
The resultant 2 D array is
given below
1 0 0
1 2 0
1 2 3
8. (a) const int R = 100, C = 100;
void Arrayconvert(int A1D[ ], int N)
{
int A2D[R][C]={0};
for(int I = 0; I<N; I++)
for (int J = 0; J <=I; J++)
A2D[I][J] = A1D[J];
}
( 1 mark for proper function header )
( 1 mark for proper use of loops)
( 1 mark for proper assignment of values)
9. 3. (a) Write a function in C++ which accepts an
integer array and its size as arguments and
replaces elements having even values with its
half and elements having odd values with twice
its value. Outside Delhi 2007 4
Example : if an array of five elements initially
contains the elements as,
3, 4, 5, 16, 9
then the function should rearrange the content
of the array as,
6, 2, 10, 8, 18
11. OR
void Display(int NUM[],int N)
{
for(int i=0;i<N;i=i+1)
NUM[i]=(NUM[i]%2!=0)?2*NUM[i]:NUM[i]/2;
}
(1 Mark for correct Function Header with
proper Arguments)
(1 Mark for correct loop)
(1 Mark for checking Even / Odd values)
(1 Mark for replacing array elements with
proper values)
12. 3. (a) Write a function in C++ which accepts an
integer array and its size as arguments and
replaces elements having odd values with
thrice its value and elements having even
values with twice its value. D 2007 4
Example : if an array of five elements initially
contains the elements as
3, 4, 5, 16, 9
then the function should rearrange the content
of the array as
9, 8, 15, 32, 27
13. 3. (a)
void Replace( int Arr[], int Size)
{
for(int i =0; i<Size; i++)
if(Arr[i]%2 != 0 )
Arr[i] *= 3;
else
Arr[i] *= 2;
}
OR
14. void Replace( int Arr[], int Size)
{
for(int i =0; i<Size; i++)
Arr[i]%2 ? Arr[i] *= 2 : Arr[i] *= 3;
}
(1 Mark for correct Function Header with
proper Arguments)
(1 Mark for correct loop)
(1 Mark for checking Even / Odd values)
(1 Mark for replacing with proper values)
15. 3. (a) Write a function in C++, which accepts
an integer array and its size as parameters
and rearranges the array in reverse.
Delhi 2008 4
Example: if an array of nine elements initially
contains the elements as
4, 2, 5, 1, 6, 7, 8, 12, 10
then the function should rearrange the array
as
10, 12, 8, 7, 6, 1, 5, 2, 4
16. Ans:
void Rearrange( int Arr [], int Size)
{
for (int i = 0; i<Size/2; i++)
{
int T = Arr[i];
Arr[i] = Arr[Size-1-i];
Arr[Size-1-i]=T;
}
}
OR
Any other correct equivalent function
definition
17. (1 Mark for correct Function Header with
proper Arguments)
(1 Mark for correct loop)
(2 Marks for swapping the values correctly)
Note:
Deduct ½ Mark if loop runs till Size instead of
Size/2 for swapping
Deduct ½ Mark if reversed values are stored in
another array
18. 3. (a) Write a function in C++, which
accepts an integer array and its size as
arguments and swaps the elements of every
even location with its following odd location.
OUTSIDE DELHI 2008 4
Example: if an array of nine elements initially
contains the elements as
2, 4, 1, 6, 5, 7, 9, 23, 10
then the function should rearrange the array
as
4, 2, 6, 1, 7, 5, 23, 9, 10
19. Ans:
void Display (int NUM[ ], int N)
{
int T;
for (int I=0; I<N–l; I+=2)
{
T=N[I] ;
N[I]=N[I+1] ;
N[I+1] = T ;
}
}
(1 Mark tor correct Function Header with proper Arguments)
(1 Mark for correct loop)
(2 Marks for swapping values correctly with / without a
temporary variable)
20. 3. (a) Write a function SORTPOINTS( ) in C++
to sort an array of structure Game in
escending order of Points using Bubble Sort.
Delhi
20093
Note: Assume the following definition of
structure Game
struct Game
{
long PNo; //Player Number
char PName [20] ;
long Points;
} ;
21. Sample content of the array (before sorting)
PNo PName Points
103 Ritika Kapur 3001
104 John Philip 2819
101 Razia Abbas 3451
105 Tarun Kumar 2971
Sample content of the array (after sorting)
PNo PName Points
101 Razia Abbas 3451
103 Ri tika Kapur 3001
105 Tarun Kumar 2971
104 John Philip 2819
22. Ans void SORTPOINTS(Game G[], int N)
{
Game Temp;
for (int I = 0; I<N-l; I++)
for (int J = 0; J<N-I-l; J++)
if(G[J].Points < G[J+l].Points)
{
Temp = G[J];
G[J] = G[J+l];
G[J+l] = Temp;
}
23. OR
Any other correct equivalent function definition
( ½ Mark for correct Function Header)
( ½ Mark for each correct loop)
( 1 Mark for correct comparison of adjacent
elements)
( ½ Mark for swapping the values correctly)
Note:
Deduct ½ Mark if sorted in ascending order
instead of descending order
Deduct ½ Mark if only Points is swapped instead
of the whole Structure
Deduct ½ Mark if Temp is not declared with
correct data type
24. 3. (a) Write a function SORTSCORE( ) in C++ to
sort an array of structure Examinee in
descending order of Score using Bubble Sort. 3
Note: Assume the following definition of structure
Examinee
struct Examinee
{
long RollNo;
char Name [20] ;
float Score;
} ;