SlideShare a Scribd company logo
1 of 11
For any help regarding Electrical Engineering Assignment Help
visit :- https://www.programminghomeworkhelp.com/
Email :- support@programminghomeworkhelp.com
or call us at :- +1 678 648 4277
programminghomeworkhelp.com
Problem
Averysimpletranspositioncipherencrypt(S )canbedescribedbythefollowingrules:
1. Ifthelengthof Sis1 or2, thenencrypt(S )is S.
2. IfSisastringof N characterss1s2s3. . . sNandk = IN /2j, then
enc(S) = encrypt(sk sk−1 ... s2s1)+ encrypt(sN sN−1 ... sk+1)
where+ indicatesstringconcatenation.
Forexample,encrypt("Ok") = "Ok" andencrypt("12345678") ="34127856".
Writeaprogramto implementthiscipher,givenanarbitrarytextfileinputupto 16 MB insize.Start withthe
templateprogramfoundatprovided in the file loop.data.zip as a basis for your program. Inthisprogram,youwill
seeamostlycompletefunctionto readafileinto adynamicallyallocated stringasrequiredforthisproblem.
programminghomeworkhelp.com
size t getstr( char **str, FILE *input ) {
size t chars to read = BLOCK SIZE; size t length = 0;
II ...snipped... see template file size t chars = 0;
while( ( chars = fread( *str + length, 1, chars to read, input ) ) ) { II you fill this out
}
II ...snipped... see template file return length;
}
Read through the code carefully, make sure you understand it, and complete the inner part of the while loop.
Look up realloc andthe <string.h> header. If you have any questions about the provided code or don’tknow
why something is structured the way it is, pleaseaskabout it on Piazza.
Youwill alsoseeanemptyfunction“encrypt”,whichyoushouldfillout.
void encrypt( char *string, size t length ) {
II you fill this out
}
Resource Limits
Forthisproblemyouareallotted3secondsof runtimeandupto 32MB of RAM.
Input Format
Lines 1. ..: The whole file (can be any number of lines) should be read in asa string.
21
aeyrleT sttf!enn aod
Test
early
and often!
Output Format
Line1: One integer:thetotalnumberof charactersinthestring Lines
2. . . :The encipheredstring.
Output Explanation
Here’seachcharacterinthestringaswearesupposedto readit in, separatedwith ‘.’ sowecanseethe newlines
andspaces:
.T.e.s.t.n.e.a.r.l.y.n.a.n.d. .o.f.t.e.n.!.
The stringisfirstsplitinhalfandtheneachhalfreversed,andthefunctioncalledrecursively;youcan seethe
recursiongoingonhere:
.y.l.r.a.e.n.t.s.e.T. .!.n.e.t..f.o. .d.n.a.n.
.n.a.n.d. .o.
.e.a.r.l.y.
.a.e. .y.l.r
I 
.T.e.s.t.n.
.e.T. .n.t.s.
I 
.f.t.e.n.!.
.t.f. .!.n.e
I 
.y. .r.l. .n. .s.t. .!. .e.n. I 
.n.a.n. .o. .d.


I 
.n. .n.a. .o. .d. .
This diagrammakesit lookabit morecomplicatedthanit actuallyis.Youcanseethatthesampleis correct by
reading off the leaves of the tree from left to right–it’s the enciphered string we want.
.a.e.y.r.l.e.T.n.s.t.t.f.!.e.n.n.n.a.o.d. .
programminghomeworkhelp.com
Solution
/*PROG: matrix2
LANG: C
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct Matrix_s {
size_t R, C;
int *index;
} Matrix;
Matrix*
allocate_matrix( size_t R, siz
e_t C ) {
Matrix *matrix
= malloc( sizeof( Matrix ) );
matrix->R = R;
matrix->C = C;
matrix->index = malloc( R *
C * sizeof( int ) );
return matrix;
}
programminghomeworkhelp.com
void destroy_matrix(
Matrix *matrix ) {
free( matrix->index );
free( matrix );
}
typedef enum {
REGULAR = 0,
TRANSPOSE = 1
} Transpose;
// Allowing reading a
matrix in as either
regular or transposed
Matrix*
read_matrix( FILE *inp
ut, Transpose orient ) {
size_t R, C;
fscanf( input, "%zu
%zu", &R, &C );
Matrix *matrix =
NULL;
programminghomeworkhelp.com
if( orient == REGULAR
) {
matrix =
allocate_matrix( R, C );
for( size_t r = 0; r <
matrix->R; ++r ) {
for( size_t c = 0; c <
matrix->C; ++c ) {
fscanf( input, "%d",
&matrix->index[c + r *
C] );
}
}
} else if( orient ==
TRANSPOSE ) {
matrix =
allocate_matrix( C, R );
for( size_t r = 0; r <
matrix->C; ++r ) {
for( size_t c = 0; c <
matrix->R; ++c ) {
fscanf( input, "%d",
&matrix->index[r + c *
R] );
}
}
programminghomeworkhelp.com
} else {
fprintf( stderr, "Error: unknown
orientation %d.n", orient );
exit( EXIT_FAILURE );
}
return matrix;
}
void print_matrix( FILE *output,
Matrix *matrix ) {
fprintf( output, "%zu %zun", matrix-
>R, matrix->C );
for( size_t r = 0; r < matrix->R; ++r )
{
for( size_t c = 0; c < matrix->C - 1;
++c ) {
fprintf( output, "%d ", matrix-
>index[c + r * matrix->C] );
}
fprintf( output, "%dn", matrix-
>index[matrix->C - 1 + r * matrix->C]
);
}
}
programminghomeworkhelp.com
Matrix* product_matrix(
Matrix *a, Matrix *b ) {
if( a->C != b->C ) {
printf( "Error: tried to
multiply
(%zux%zu)x(%zux%zu)n",
a->R, a->C, b->C, b->R );
exit( EXIT_FAILURE );
}
Matrix *prod =
allocate_matrix( a->R, b->R
);
size_t nRows = prod->R,
nCols = prod->C, nInner = a-
>C;
for( size_t r = 0; r < nRows;
++r ) {
for( size_t c = 0; c <
nCols; ++c ) {
prod->index[c + r *
nCols] = 0;
for( size_t i = 0; i <
nInner; ++i ) {
prod->index[c + r *
nCols] += a->index[i + r *
programminghomeworkhelp.com
>index[i + c * nInner];
}
}
}
return prod;
}
int main(void) {
FILE *fin
= fopen( "matrix2.in", "r" );
if( fin == NULL ) {
printf( "Error: could not
open matrix2.inn" );
exit( EXIT_FAILURE );
}
Matrix *a = read_matrix(
fin, REGULAR );
Matrix *b = read_matrix(
fin, TRANSPOSE );
fclose( fin );
Matrix *c = product_matrix(
programminghomeworkhelp.com
a, b );
FILE *output
= fopen( "matrix2.out", "w" );
if( output == NULL ) {
printf( "Error: could not
open matrix2.outn" );
exit( EXIT_FAILURE );
}
print_matrix( output, c );
fclose( output );
destroy_matrix( a );
destroy_matrix( b );
destroy_matrix( c );
return 0;
}
programminghomeworkhelp.com
Below is the output using the
test data:
matrix2: 1: OK [0.006
seconds] 2: OK [0.007
seconds] 3: OK [0.007
seconds] 4: OK [0.019
seconds] 5: OK [0.017
seconds] 6: OK [0.109
seconds] 7: OK [0.178
seconds] 8: OK [0.480
seconds] 9: OK [0.791
seconds]10: OK [1.236
seconds]11: OK [2.088
seconds]
programminghomeworkhelp.com

More Related Content

What's hot

10. Getting Spatial
10. Getting Spatial10. Getting Spatial
10. Getting SpatialFAO
 
Linear models
Linear modelsLinear models
Linear modelsFAO
 
Vectors data frames
Vectors data framesVectors data frames
Vectors data framesFAO
 

What's hot (20)

Control System Homework Help
Control System Homework HelpControl System Homework Help
Control System Homework Help
 
Fourier Transform Assignment Help
Fourier Transform Assignment HelpFourier Transform Assignment Help
Fourier Transform Assignment Help
 
Signal Processing Assignment Help
Signal Processing Assignment HelpSignal Processing Assignment Help
Signal Processing Assignment Help
 
Probability Assignment Help
Probability Assignment HelpProbability Assignment Help
Probability Assignment Help
 
Machnical Engineering Assignment Help
Machnical Engineering Assignment HelpMachnical Engineering Assignment Help
Machnical Engineering Assignment Help
 
Data Analysis Homework Help
Data Analysis Homework HelpData Analysis Homework Help
Data Analysis Homework Help
 
Algorithm Homework Help
Algorithm Homework HelpAlgorithm Homework Help
Algorithm Homework Help
 
Electrical Engineering Assignment Help
Electrical Engineering Assignment HelpElectrical Engineering Assignment Help
Electrical Engineering Assignment Help
 
Statistics Assignment Help
Statistics Assignment HelpStatistics Assignment Help
Statistics Assignment Help
 
Algorithm Assignment Help
Algorithm Assignment HelpAlgorithm Assignment Help
Algorithm Assignment Help
 
Software Construction Assignment Help
Software Construction Assignment HelpSoftware Construction Assignment Help
Software Construction Assignment Help
 
Computer Science Assignment Help
Computer Science Assignment HelpComputer Science Assignment Help
Computer Science Assignment Help
 
Signal Processing Assignment Help
Signal Processing Assignment HelpSignal Processing Assignment Help
Signal Processing Assignment Help
 
10. Getting Spatial
10. Getting Spatial10. Getting Spatial
10. Getting Spatial
 
Linear models
Linear modelsLinear models
Linear models
 
Matlab Assignment Help
Matlab Assignment HelpMatlab Assignment Help
Matlab Assignment Help
 
Computer Science Assignment Help
Computer Science Assignment Help Computer Science Assignment Help
Computer Science Assignment Help
 
Analysis of Algorithm
Analysis of AlgorithmAnalysis of Algorithm
Analysis of Algorithm
 
Diffusion Homework Help
Diffusion Homework HelpDiffusion Homework Help
Diffusion Homework Help
 
Vectors data frames
Vectors data framesVectors data frames
Vectors data frames
 

Similar to Programming Assignment Help

Best C++ Programming Homework Help
Best C++ Programming Homework HelpBest C++ Programming Homework Help
Best C++ Programming Homework HelpC++ Homework Help
 
Introduction to Compiler Development
Introduction to Compiler DevelopmentIntroduction to Compiler Development
Introduction to Compiler DevelopmentLogan Chien
 
Data structures notes for college students btech.pptx
Data structures notes for college students btech.pptxData structures notes for college students btech.pptx
Data structures notes for college students btech.pptxKarthikVijay59
 
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
1sequences and sampling. Suppose we went to sample the x-axis from X.pdfrushabhshah600
 
Scala as a Declarative Language
Scala as a Declarative LanguageScala as a Declarative Language
Scala as a Declarative Languagevsssuresh
 
So I am writing a CS code for a project and I keep getting cannot .pdf
So I am writing a CS code for a project and I keep getting cannot .pdfSo I am writing a CS code for a project and I keep getting cannot .pdf
So I am writing a CS code for a project and I keep getting cannot .pdfezonesolutions
 
C Programming Interview Questions
C Programming Interview QuestionsC Programming Interview Questions
C Programming Interview QuestionsGradeup
 
VCE Unit 01 (2).pptx
VCE Unit 01 (2).pptxVCE Unit 01 (2).pptx
VCE Unit 01 (2).pptxskilljiolms
 
HW 5-RSAascii2str.mfunction str = ascii2str(ascii) .docx
HW 5-RSAascii2str.mfunction str = ascii2str(ascii)        .docxHW 5-RSAascii2str.mfunction str = ascii2str(ascii)        .docx
HW 5-RSAascii2str.mfunction str = ascii2str(ascii) .docxwellesleyterresa
 
Dam31303 dti2143 lab sheet 7
Dam31303 dti2143 lab sheet 7Dam31303 dti2143 lab sheet 7
Dam31303 dti2143 lab sheet 7alish sha
 
Native interfaces for R
Native interfaces for RNative interfaces for R
Native interfaces for RSeth Falcon
 
PVS-Studio team experience: checking various open source projects, or mistake...
PVS-Studio team experience: checking various open source projects, or mistake...PVS-Studio team experience: checking various open source projects, or mistake...
PVS-Studio team experience: checking various open source projects, or mistake...Andrey Karpov
 
3Arrays, Declarations, Expressions, Statements, Symbolic constant.pptx
3Arrays, Declarations, Expressions, Statements, Symbolic constant.pptx3Arrays, Declarations, Expressions, Statements, Symbolic constant.pptx
3Arrays, Declarations, Expressions, Statements, Symbolic constant.pptxganeshkarthy
 
Chapter 7 functions (c)
Chapter 7 functions (c)Chapter 7 functions (c)
Chapter 7 functions (c)hhliu
 
Hacking parse.y (RubyKansai38)
Hacking parse.y (RubyKansai38)Hacking parse.y (RubyKansai38)
Hacking parse.y (RubyKansai38)ujihisa
 

Similar to Programming Assignment Help (20)

Best C++ Programming Homework Help
Best C++ Programming Homework HelpBest C++ Programming Homework Help
Best C++ Programming Homework Help
 
Introduction to Compiler Development
Introduction to Compiler DevelopmentIntroduction to Compiler Development
Introduction to Compiler Development
 
Data structures notes for college students btech.pptx
Data structures notes for college students btech.pptxData structures notes for college students btech.pptx
Data structures notes for college students btech.pptx
 
C-programs
C-programsC-programs
C-programs
 
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
 
Scala as a Declarative Language
Scala as a Declarative LanguageScala as a Declarative Language
Scala as a Declarative Language
 
C Programming Homework Help
C Programming Homework HelpC Programming Homework Help
C Programming Homework Help
 
So I am writing a CS code for a project and I keep getting cannot .pdf
So I am writing a CS code for a project and I keep getting cannot .pdfSo I am writing a CS code for a project and I keep getting cannot .pdf
So I am writing a CS code for a project and I keep getting cannot .pdf
 
C Programming Interview Questions
C Programming Interview QuestionsC Programming Interview Questions
C Programming Interview Questions
 
VCE Unit 01 (2).pptx
VCE Unit 01 (2).pptxVCE Unit 01 (2).pptx
VCE Unit 01 (2).pptx
 
HW 5-RSAascii2str.mfunction str = ascii2str(ascii) .docx
HW 5-RSAascii2str.mfunction str = ascii2str(ascii)        .docxHW 5-RSAascii2str.mfunction str = ascii2str(ascii)        .docx
HW 5-RSAascii2str.mfunction str = ascii2str(ascii) .docx
 
Dam31303 dti2143 lab sheet 7
Dam31303 dti2143 lab sheet 7Dam31303 dti2143 lab sheet 7
Dam31303 dti2143 lab sheet 7
 
Native interfaces for R
Native interfaces for RNative interfaces for R
Native interfaces for R
 
Report Cryptography
Report CryptographyReport Cryptography
Report Cryptography
 
PVS-Studio team experience: checking various open source projects, or mistake...
PVS-Studio team experience: checking various open source projects, or mistake...PVS-Studio team experience: checking various open source projects, or mistake...
PVS-Studio team experience: checking various open source projects, or mistake...
 
3Arrays, Declarations, Expressions, Statements, Symbolic constant.pptx
3Arrays, Declarations, Expressions, Statements, Symbolic constant.pptx3Arrays, Declarations, Expressions, Statements, Symbolic constant.pptx
3Arrays, Declarations, Expressions, Statements, Symbolic constant.pptx
 
Chapter 7 functions (c)
Chapter 7 functions (c)Chapter 7 functions (c)
Chapter 7 functions (c)
 
C Programming Example
C Programming Example C Programming Example
C Programming Example
 
Hacking parse.y (RubyKansai38)
Hacking parse.y (RubyKansai38)Hacking parse.y (RubyKansai38)
Hacking parse.y (RubyKansai38)
 
week-3x
week-3xweek-3x
week-3x
 

More from Programming Homework Help

Design and Analysis of Algorithms Assignment Help
Design and Analysis of Algorithms Assignment HelpDesign and Analysis of Algorithms Assignment Help
Design and Analysis of Algorithms Assignment HelpProgramming Homework Help
 
programminghomeworkhelp.com_Advanced Algorithms Homework Help.pptx
programminghomeworkhelp.com_Advanced Algorithms Homework Help.pptxprogramminghomeworkhelp.com_Advanced Algorithms Homework Help.pptx
programminghomeworkhelp.com_Advanced Algorithms Homework Help.pptxProgramming Homework Help
 

More from Programming Homework Help (20)

C Assignment Help
C Assignment HelpC Assignment Help
C Assignment Help
 
Python Question - Python Assignment Help
Python Question - Python Assignment HelpPython Question - Python Assignment Help
Python Question - Python Assignment Help
 
Best Algorithms Assignment Help
Best Algorithms Assignment Help Best Algorithms Assignment Help
Best Algorithms Assignment Help
 
Design and Analysis of Algorithms Assignment Help
Design and Analysis of Algorithms Assignment HelpDesign and Analysis of Algorithms Assignment Help
Design and Analysis of Algorithms Assignment Help
 
Algorithm Homework Help
Algorithm Homework HelpAlgorithm Homework Help
Algorithm Homework Help
 
programminghomeworkhelp.com_Advanced Algorithms Homework Help.pptx
programminghomeworkhelp.com_Advanced Algorithms Homework Help.pptxprogramminghomeworkhelp.com_Advanced Algorithms Homework Help.pptx
programminghomeworkhelp.com_Advanced Algorithms Homework Help.pptx
 
Algorithm Homework Help
Algorithm Homework HelpAlgorithm Homework Help
Algorithm Homework Help
 
Algorithms Design Assignment Help
Algorithms Design Assignment HelpAlgorithms Design Assignment Help
Algorithms Design Assignment Help
 
Algorithms Design Homework Help
Algorithms Design Homework HelpAlgorithms Design Homework Help
Algorithms Design Homework Help
 
Algorithm Assignment Help
Algorithm Assignment HelpAlgorithm Assignment Help
Algorithm Assignment Help
 
Algorithm Homework Help
Algorithm Homework HelpAlgorithm Homework Help
Algorithm Homework Help
 
C Homework Help
C Homework HelpC Homework Help
C Homework Help
 
C Homework Help
C Homework HelpC Homework Help
C Homework Help
 
Algorithm Assignment Help
Algorithm Assignment HelpAlgorithm Assignment Help
Algorithm Assignment Help
 
C Assignment Help
C Assignment HelpC Assignment Help
C Assignment Help
 
Programming Homework Help
Programming Homework Help Programming Homework Help
Programming Homework Help
 
C Programming Homework Help
C Programming Homework HelpC Programming Homework Help
C Programming Homework Help
 
Computational Assignment Help
Computational Assignment HelpComputational Assignment Help
Computational Assignment Help
 
Computation Assignment Help
Computation Assignment Help Computation Assignment Help
Computation Assignment Help
 
Python Homework Help
Python Homework HelpPython Homework Help
Python Homework Help
 

Recently uploaded

Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 

Recently uploaded (20)

Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 

Programming Assignment Help

  • 1. For any help regarding Electrical Engineering Assignment Help visit :- https://www.programminghomeworkhelp.com/ Email :- support@programminghomeworkhelp.com or call us at :- +1 678 648 4277 programminghomeworkhelp.com
  • 2. Problem Averysimpletranspositioncipherencrypt(S )canbedescribedbythefollowingrules: 1. Ifthelengthof Sis1 or2, thenencrypt(S )is S. 2. IfSisastringof N characterss1s2s3. . . sNandk = IN /2j, then enc(S) = encrypt(sk sk−1 ... s2s1)+ encrypt(sN sN−1 ... sk+1) where+ indicatesstringconcatenation. Forexample,encrypt("Ok") = "Ok" andencrypt("12345678") ="34127856". Writeaprogramto implementthiscipher,givenanarbitrarytextfileinputupto 16 MB insize.Start withthe templateprogramfoundatprovided in the file loop.data.zip as a basis for your program. Inthisprogram,youwill seeamostlycompletefunctionto readafileinto adynamicallyallocated stringasrequiredforthisproblem. programminghomeworkhelp.com size t getstr( char **str, FILE *input ) { size t chars to read = BLOCK SIZE; size t length = 0; II ...snipped... see template file size t chars = 0; while( ( chars = fread( *str + length, 1, chars to read, input ) ) ) { II you fill this out } II ...snipped... see template file return length; } Read through the code carefully, make sure you understand it, and complete the inner part of the while loop. Look up realloc andthe <string.h> header. If you have any questions about the provided code or don’tknow why something is structured the way it is, pleaseaskabout it on Piazza. Youwill alsoseeanemptyfunction“encrypt”,whichyoushouldfillout. void encrypt( char *string, size t length ) { II you fill this out } Resource Limits Forthisproblemyouareallotted3secondsof runtimeandupto 32MB of RAM. Input Format Lines 1. ..: The whole file (can be any number of lines) should be read in asa string.
  • 3. 21 aeyrleT sttf!enn aod Test early and often! Output Format Line1: One integer:thetotalnumberof charactersinthestring Lines 2. . . :The encipheredstring. Output Explanation Here’seachcharacterinthestringaswearesupposedto readit in, separatedwith ‘.’ sowecanseethe newlines andspaces: .T.e.s.t.n.e.a.r.l.y.n.a.n.d. .o.f.t.e.n.!. The stringisfirstsplitinhalfandtheneachhalfreversed,andthefunctioncalledrecursively;youcan seethe recursiongoingonhere: .y.l.r.a.e.n.t.s.e.T. .!.n.e.t..f.o. .d.n.a.n. .n.a.n.d. .o. .e.a.r.l.y. .a.e. .y.l.r I .T.e.s.t.n. .e.T. .n.t.s. I .f.t.e.n.!. .t.f. .!.n.e I .y. .r.l. .n. .s.t. .!. .e.n. I .n.a.n. .o. .d. I .n. .n.a. .o. .d. . This diagrammakesit lookabit morecomplicatedthanit actuallyis.Youcanseethatthesampleis correct by reading off the leaves of the tree from left to right–it’s the enciphered string we want. .a.e.y.r.l.e.T.n.s.t.t.f.!.e.n.n.n.a.o.d. . programminghomeworkhelp.com
  • 4. Solution /*PROG: matrix2 LANG: C */ #include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct Matrix_s { size_t R, C; int *index; } Matrix; Matrix* allocate_matrix( size_t R, siz e_t C ) { Matrix *matrix = malloc( sizeof( Matrix ) ); matrix->R = R; matrix->C = C; matrix->index = malloc( R * C * sizeof( int ) ); return matrix; } programminghomeworkhelp.com
  • 5. void destroy_matrix( Matrix *matrix ) { free( matrix->index ); free( matrix ); } typedef enum { REGULAR = 0, TRANSPOSE = 1 } Transpose; // Allowing reading a matrix in as either regular or transposed Matrix* read_matrix( FILE *inp ut, Transpose orient ) { size_t R, C; fscanf( input, "%zu %zu", &R, &C ); Matrix *matrix = NULL; programminghomeworkhelp.com
  • 6. if( orient == REGULAR ) { matrix = allocate_matrix( R, C ); for( size_t r = 0; r < matrix->R; ++r ) { for( size_t c = 0; c < matrix->C; ++c ) { fscanf( input, "%d", &matrix->index[c + r * C] ); } } } else if( orient == TRANSPOSE ) { matrix = allocate_matrix( C, R ); for( size_t r = 0; r < matrix->C; ++r ) { for( size_t c = 0; c < matrix->R; ++c ) { fscanf( input, "%d", &matrix->index[r + c * R] ); } } programminghomeworkhelp.com
  • 7. } else { fprintf( stderr, "Error: unknown orientation %d.n", orient ); exit( EXIT_FAILURE ); } return matrix; } void print_matrix( FILE *output, Matrix *matrix ) { fprintf( output, "%zu %zun", matrix- >R, matrix->C ); for( size_t r = 0; r < matrix->R; ++r ) { for( size_t c = 0; c < matrix->C - 1; ++c ) { fprintf( output, "%d ", matrix- >index[c + r * matrix->C] ); } fprintf( output, "%dn", matrix- >index[matrix->C - 1 + r * matrix->C] ); } } programminghomeworkhelp.com
  • 8. Matrix* product_matrix( Matrix *a, Matrix *b ) { if( a->C != b->C ) { printf( "Error: tried to multiply (%zux%zu)x(%zux%zu)n", a->R, a->C, b->C, b->R ); exit( EXIT_FAILURE ); } Matrix *prod = allocate_matrix( a->R, b->R ); size_t nRows = prod->R, nCols = prod->C, nInner = a- >C; for( size_t r = 0; r < nRows; ++r ) { for( size_t c = 0; c < nCols; ++c ) { prod->index[c + r * nCols] = 0; for( size_t i = 0; i < nInner; ++i ) { prod->index[c + r * nCols] += a->index[i + r * programminghomeworkhelp.com
  • 9. >index[i + c * nInner]; } } } return prod; } int main(void) { FILE *fin = fopen( "matrix2.in", "r" ); if( fin == NULL ) { printf( "Error: could not open matrix2.inn" ); exit( EXIT_FAILURE ); } Matrix *a = read_matrix( fin, REGULAR ); Matrix *b = read_matrix( fin, TRANSPOSE ); fclose( fin ); Matrix *c = product_matrix( programminghomeworkhelp.com
  • 10. a, b ); FILE *output = fopen( "matrix2.out", "w" ); if( output == NULL ) { printf( "Error: could not open matrix2.outn" ); exit( EXIT_FAILURE ); } print_matrix( output, c ); fclose( output ); destroy_matrix( a ); destroy_matrix( b ); destroy_matrix( c ); return 0; } programminghomeworkhelp.com
  • 11. Below is the output using the test data: matrix2: 1: OK [0.006 seconds] 2: OK [0.007 seconds] 3: OK [0.007 seconds] 4: OK [0.019 seconds] 5: OK [0.017 seconds] 6: OK [0.109 seconds] 7: OK [0.178 seconds] 8: OK [0.480 seconds] 9: OK [0.791 seconds]10: OK [1.236 seconds]11: OK [2.088 seconds] programminghomeworkhelp.com