SlideShare a Scribd company logo
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

PPTX
Computer Science Assignment Help
PPTX
statistics assignment help
PPTX
Computing and Data Analysis for Environmental Applications
PPTX
Electrical Engineering Exam Help
PPTX
Statistics Assignment Help
PPTX
Mechanical Engineering Assignment Help
PPTX
Mechanical Engineering Homework Help
PPT
Environmental Engineering Assignment Help
Computer Science Assignment Help
statistics assignment help
Computing and Data Analysis for Environmental Applications
Electrical Engineering Exam Help
Statistics Assignment Help
Mechanical Engineering Assignment Help
Mechanical Engineering Homework Help
Environmental Engineering Assignment Help

What's hot (20)

PPTX
Control System Homework Help
PPTX
Fourier Transform Assignment Help
PPTX
Signal Processing Assignment Help
PPTX
Probability Assignment Help
PPTX
Machnical Engineering Assignment Help
PPTX
Data Analysis Homework Help
PPTX
Algorithm Homework Help
PPTX
Electrical Engineering Assignment Help
PPTX
Statistics Assignment Help
PPTX
Algorithm Assignment Help
PPTX
Software Construction Assignment Help
PPTX
Computer Science Assignment Help
PPTX
Signal Processing Assignment Help
PDF
10. Getting Spatial
 
PDF
Linear models
 
PPTX
Matlab Assignment Help
PPTX
Computer Science Assignment Help
PPT
Analysis of Algorithm
PPTX
Diffusion Homework Help
PDF
Vectors data frames
 
Control System Homework Help
Fourier Transform Assignment Help
Signal Processing Assignment Help
Probability Assignment Help
Machnical Engineering Assignment Help
Data Analysis Homework Help
Algorithm Homework Help
Electrical Engineering Assignment Help
Statistics Assignment Help
Algorithm Assignment Help
Software Construction Assignment Help
Computer Science Assignment Help
Signal Processing Assignment Help
10. Getting Spatial
 
Linear models
 
Matlab Assignment Help
Computer Science Assignment Help
Analysis of Algorithm
Diffusion Homework Help
Vectors data frames
 
Ad

Similar to Programming Assignment Help (20)

PPTX
Best C++ Programming Homework Help
PDF
Introduction to Compiler Development
PPTX
Data structures notes for college students btech.pptx
DOC
C-programs
PDF
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
ODP
Scala as a Declarative Language
PPTX
C Programming Homework Help
PDF
So I am writing a CS code for a project and I keep getting cannot .pdf
PDF
C Programming Interview Questions
PPTX
VCE Unit 01 (2).pptx
DOCX
HW 5-RSAascii2str.mfunction str = ascii2str(ascii) .docx
DOCX
Dam31303 dti2143 lab sheet 7
PDF
Native interfaces for R
DOCX
CDMA simulation code for wireless Network.docx
PDF
Astronomical data analysis by python.pdf
PDF
Report Cryptography
PPTX
PVS-Studio team experience: checking various open source projects, or mistake...
PPTX
3Arrays, Declarations, Expressions, Statements, Symbolic constant.pptx
PPTX
Chapter 7 functions (c)
PPTX
C Programming Example
Best C++ Programming Homework Help
Introduction to Compiler Development
Data structures notes for college students btech.pptx
C-programs
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
Scala as a Declarative Language
C Programming Homework Help
So I am writing a CS code for a project and I keep getting cannot .pdf
C Programming Interview Questions
VCE Unit 01 (2).pptx
HW 5-RSAascii2str.mfunction str = ascii2str(ascii) .docx
Dam31303 dti2143 lab sheet 7
Native interfaces for R
CDMA simulation code for wireless Network.docx
Astronomical data analysis by python.pdf
Report Cryptography
PVS-Studio team experience: checking various open source projects, or mistake...
3Arrays, Declarations, Expressions, Statements, Symbolic constant.pptx
Chapter 7 functions (c)
C Programming Example
Ad

More from Programming Homework Help (20)

PPTX
Data Structures and Algorithm: Sample Problems with Solution
PPTX
Seasonal Decomposition of Time Series Data
PPTX
Solving Haskell Assignment: Engaging Challenges and Solutions for University ...
PPTX
Exploring Control Flow: Harnessing While Loops in Python
PPTX
Java Assignment Sample: Building Software with Objects, Graphics, Containers,...
PPTX
C Assignment Help
PPTX
Python Question - Python Assignment Help
PPTX
Best Algorithms Assignment Help
PPTX
Design and Analysis of Algorithms Assignment Help
PPTX
Algorithm Homework Help
PPTX
programminghomeworkhelp.com_Advanced Algorithms Homework Help.pptx
PPTX
Algorithm Homework Help
PPTX
Algorithms Design Assignment Help
PPTX
Algorithms Design Homework Help
PPTX
Algorithm Assignment Help
PPTX
Algorithm Homework Help
PPTX
C Homework Help
PPTX
C Homework Help
PPTX
Algorithm Assignment Help
PPTX
C Assignment Help
Data Structures and Algorithm: Sample Problems with Solution
Seasonal Decomposition of Time Series Data
Solving Haskell Assignment: Engaging Challenges and Solutions for University ...
Exploring Control Flow: Harnessing While Loops in Python
Java Assignment Sample: Building Software with Objects, Graphics, Containers,...
C Assignment Help
Python Question - Python Assignment Help
Best Algorithms Assignment Help
Design and Analysis of Algorithms Assignment Help
Algorithm Homework Help
programminghomeworkhelp.com_Advanced Algorithms Homework Help.pptx
Algorithm Homework Help
Algorithms Design Assignment Help
Algorithms Design Homework Help
Algorithm Assignment Help
Algorithm Homework Help
C Homework Help
C Homework Help
Algorithm Assignment Help
C Assignment Help

Recently uploaded (20)

PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
Classroom Observation Tools for Teachers
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
Basic Mud Logging Guide for educational purpose
PDF
01-Introduction-to-Information-Management.pdf
PDF
Pre independence Education in Inndia.pdf
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
master seminar digital applications in india
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
RMMM.pdf make it easy to upload and study
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PPTX
Cell Types and Its function , kingdom of life
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PPH.pptx obstetrics and gynecology in nursing
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Supply Chain Operations Speaking Notes -ICLT Program
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Classroom Observation Tools for Teachers
102 student loan defaulters named and shamed – Is someone you know on the list?
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Basic Mud Logging Guide for educational purpose
01-Introduction-to-Information-Management.pdf
Pre independence Education in Inndia.pdf
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
master seminar digital applications in india
Anesthesia in Laparoscopic Surgery in India
RMMM.pdf make it easy to upload and study
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Cell Types and Its function , kingdom of life
Module 4: Burden of Disease Tutorial Slides S2 2025

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