Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4019872
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:09:30+00:00 2026-05-20T10:09:30+00:00

I want to create a program that creates .txt files with random characters, but

  • 0

I want to create a program that creates “.txt” files with random characters, but with the possibility of creating transposed “files”. Next, I add an example of two “.txt” files as I intend to do.

FILE1

A|B|C|D|E|F|G|

H|I|J|K|L|M|N|

O|P|Q|R|S|T|U|

V|W|Z|1|2|3|4|

FILE2 (FILE1 transpossed)

A|H|O|V|

B|I|P|W|

C|J|Q|Z|

D|K|R|1|

E|L|S|2|

F|M|T|3|

G|N|U|4|

And now I add the code I have writen so that you can have a look and give me some ideas about how do it, what do modify and so on.

#include<iostream>
#include<fstream>
#include<stdio.h>
#include<string>
#include<ctime>

using namespace std;

int main()
{
    int rows, columns, element1;

    char word[10];

    ofstream myfile ("File 1.txt");
    if(myfile)
        srand(1);
    for(rows=0;rows<10;rows++)
    {
        for(columns=0;columns<30;columns++)
        {
            element1 = rand() % 100000 + 1;
            int len = rand () % 4 + 4;
            word [len] = 0;
            while (len) word [--len] = 'A' + rand () % 58;

            myfile<<element1<<word;
            myfile<<"|";
        }
        myfile<<endl;

    }
    myfile.close();


    ofstream myfileS ("File 2.txt");
    if(myfileS)
        srand(1);
    for(columns=0;columns<30;columns++)
    {
        for(rows=0;rows<10;rows++)
        {

            element1 = rand() % 100000 + 1;
            int len = rand () % 4 + 4;
            word [len] = 0;
            while (len) word [--len] = 'A' + rand () % 58;

            myfileS<<element1<<word;
            myfileS<<"|";
        }
        myfileS<<endl;
    }
    myfile.close();



    system("pause");
    return 0;

}

Thanks for your help!

SOLUTION OF MY DOUBT

#include<iostream>
#include<fstream>
#include<stdio.h>
#include<string>
#include<ctime>
#include<sstream>

using namespace std;

int main()
{
int rows, columns, rowsMax, columnsMax; 
int element1;

    char word[10];

int a=0;

cout<<"Write the number of rows of your table: ";
cin>>rowsMax;

cout<<"Write the number of columns of your table: ";
cin>>columnsMax;

int answer;
cout<<"Do you want to create the transposed table??? (1 -> yes, 2 -> no): ";
cin>>answer;

string matriz[7][5]; // string matriz[rowsMax][columnsMax]; I should modify this in every query

string table ("Table1.txt");
ofstream myfile (table);
if(myfile.is_open())
srand(1);
myfile<<id<<"|"<<type<<"|"<<columnsMax<<endl;
for(rows=0;rows<rowsMax;rows++)
{
    for(columns=0;columns<columnsMax;columns++)
    {
        element1 = rand() % 100000 + 1;
        int len = rand () % 4 + 4;
        word [len] = 0;
        while (len) word [--len] = 'A' + rand () % 58;
        myfile<<element1<<word;
        myfile<<"|";

        std::stringstream ss;
            ss<<element1;

        string mat;
        mat +=ss.str();
        mat +=word;
        matriz[rows][columns]= mat;
    }
    myfile<<endl;

}
myfile.close();


while(answer==1)
{
    string table ("Table");
    table +=id;
    table +="(transposed)";
    table +=".txt";
    ofstream myfile (table);
    if(myfile.is_open())
    myfile<<id<<"|2|"<<columnsMax<<endl;
    for(int k=0;k<5;k++)
    {
            for(int j=0;j<7;j++)
        {
            myfile<<matriz[j][k]<<"|";
        }
            myfile<<endl;
    }
    answer=2;
}
system("pause");
return 0;

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T10:09:31+00:00Added an answer on May 20, 2026 at 10:09 am
    • to create a transposed version of file1.txt, you’ll have to keep its content in memory and visit that content in a transposed way.

    • when you write

      if(myfileS.is_open())
      srand(time(0));
      

      you just conditionalize the srand of the fact that the file is open or not. Not what follows. I’d put braces around everything.

    • the best way to test the status of an IOStream is just to use it as a condition

      if (myfileS)
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create a program that requests from the user 10 grades and
<flavor> I want to create a spelling test program for my grade schoolers that
I want to be able to create a program that will take a list
I want to create a program that modifies another c++ source,compiles it and runs
I want to create a PHP program that could create a .php file that
I am trying to create a program that tracks bike intervals and creates a
Hi I want to create a program that helps me to create an email
I want to create a C# program to provision Windows Mobile devices. I have
I want to create a very simple HTML/AJAX based GUI for a Python program.
I want to create a function that performs a function passed by parameter on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.