What's new

C# Sa mga expert sa programming Pahelp po please due today 5pm THANKYOU

heyz

Leecher
Joined
May 19, 2022
Posts
3
Reaction
0
Utilize array for this laboratory activity. Create a program that ask the user to enter 20 lines for a poem. After entering the last line, ask the user how many lines does each stanza will be composed of. For example, if the user entered 3 lines per stanza, the poem to be printed (consisting of the lines entered previously) shall be consist of 7 stanzas where 6 stanzas are consist of exactly 3 lines while the 7th stanza is consist of 2 lones only.
 
Dahil di ako busy. Eto ituloy mo nalang.
Di ko sure kung ayan yung need mo pero according sa instructions, split yung given 20 lines into group by chunkSize

Note: remove mo nalang yung lines.Add(RandomString(length: 10)); kung tapos mo ng itest then manual input kana.

C#:
int numberOfLines = 20;

List<string> lines = new();
Console.WriteLine($"Enter the {numberOfLines} lines of poem");

for (int i = 1; i < numberOfLines + 1; i++) {
    lines.Add(RandomString(length: 10));
    // Console.Write($"L{i}: ");
    // lines.Add(Console.ReadLine());
}

Console.Write("Enter number of lines for each stanza: ");
int chunkSize = Convert.ToInt32(Console.ReadLine());

var chunks = SplitByChunk(lines, chunkSize);

foreach (string[] chunk in chunks) {
    foreach (var c in chunk)
        Console.WriteLine(c);
    Console.WriteLine();
}

static string[][] SplitByChunk(IEnumerable<string> source, int chunkSize) {
    int i = 0;
    return source.GroupBy(s => i++ / chunkSize).Select(g => g.ToArray()).ToArray();
}

static string RandomString(int length) {
    var random = new Random();
    const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    return new string(Enumerable.Repeat(chars, length)
        .Select(s => s[random.Next(s.Length)]).ToArray());
}


Dahil random lang, eto magiging output niyan

Code:
79OLEG0KL1
DTOD0N6A0U
L6CAXZ2XCR

CJJ4IOB6XK
XV7MH6Y62K
I7WFQVV9XX

HVLRZD37TS
F4X6VRHDIQ
00V7YRTJV0

2LDDXDAAJ8
FJIQAZ5CQV
E2JAG06YQW

WZJY4W1C6F
XUH0GDDWJ5
SVY6L8PCNV

7VSPA964ZT
WM84M04C89
HCSCZZSESO

RF6IEQ84VM
8698EI176O

Note: Di ako expert, just wanted to help a little
 
Last edited:
Ang galing walang feedback kung nag work ba o hindi haha pero di bale na.
Pero kahit dummy account lang gamit mo, sana matuto karin mag feedback. Hindi logout then switch to main account agad pagkuha ng solution =D
 

dee-u

Elite
Ang galing walang feedback kung nag work ba o hindi haha pero di bale na.
Pero kahit dummy account lang gamit mo, sana matuto karin mag feedback. Hindi logout then switch to main account agad pagkuha ng solution =D
Meron na rin akong binigyan ng mga code dito, wala man lang ding thank you, feedback o kahit like man lang sa code na ibinigay ko kaya minsan nakakawalang-gana, hehe
 
Meron na rin akong binigyan ng mga code dito, wala man lang ding thank you, feedback o kahit like man lang sa code na ibinigay ko kaya minsan nakakawalang-gana, hehe

Hahaha yun na nga eh, nakakawalang gana yung sila na may kailangan tapos pag nakuha na, tatakbo nalang agad. Pero kahit papaano karamihan may feedback.
Kaya nakakadala narin tumulong lalo na sa dummy lords =D

Na test ko program mo lods, nagana. Galing! IT 1st year ako C din pinagaaralan namin hehehe. Pagaaralan ko to master
Nice thanks for confirmation.
 

heyz

Leecher
sorry po 1st time ko lang gamitin tong page na ito kaya diko alam kung saan pwede magreply
 

snap

Honorary Poster
Dahil di ako busy. Eto ituloy mo nalang.
Di ko sure kung ayan yung need mo pero according sa instructions, split yung given 20 lines into group by chunkSize

Note: remove mo nalang yung lines.Add(RandomString(length: 10)); kung tapos mo ng itest then manual input kana.

C#:
int numberOfLines = 20;

List<string> lines = new();
Console.WriteLine($"Enter the {numberOfLines} lines of poem");

for (int i = 1; i < numberOfLines + 1; i++) {
    lines.Add(RandomString(length: 10));
    // Console.Write($"L{i}: ");
    // lines.Add(Console.ReadLine());
}

Console.Write("Enter number of lines for each stanza: ");
int chunkSize = Convert.ToInt32(Console.ReadLine());

var chunks = SplitByChunk(lines, chunkSize);

foreach (string[] chunk in chunks) {
    foreach (var c in chunk)
        Console.WriteLine(c);
    Console.WriteLine();
}

static string[][] SplitByChunk(IEnumerable<string> source, int chunkSize) {
    int i = 0;
    return source.GroupBy(s => i++ / chunkSize).Select(g => g.ToArray()).ToArray();
}

static string RandomString(int length) {
    var random = new Random();
    const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    return new string(Enumerable.Repeat(chars, length)
        .Select(s => s[random.Next(s.Length)]).ToArray());
}


Dahil random lang, eto magiging output niyan

Code:
79OLEG0KL1
DTOD0N6A0U
L6CAXZ2XCR

CJJ4IOB6XK
XV7MH6Y62K
I7WFQVV9XX

HVLRZD37TS
F4X6VRHDIQ
00V7YRTJV0

2LDDXDAAJ8
FJIQAZ5CQV
E2JAG06YQW

WZJY4W1C6F
XUH0GDDWJ5
SVY6L8PCNV

7VSPA964ZT
WM84M04C89
HCSCZZSESO

RF6IEQ84VM
8698EI176O

Note: Di ako expert, just wanted to help a little
ang galing mo sir wala akong alam sa ganito

Hahaha yun na nga eh, nakakawalang gana yung sila na may kailangan tapos pag nakuha na, tatakbo nalang agad. Pero kahit papaano karamihan may feedback.
Kaya nakakadala narin tumulong lalo na sa dummy lords =D


Nice thanks for confirmation.gus
Hahaha yun na nga eh, nakakawalang gana yung sila na may kailangan tapos pag nakuha na, tatakbo nalang agad. Pero kahit papaano karamihan may feedback.
Kaya nakakadala narin tumulong lalo na sa dummy lords =D


Nice thanks for confirmation.
boss anong course po maererecommend nyo sa tulad kong baguhan gusto ko matutunan paano mag coding
 
Top