| |

VerySource

 Forgot password?
 Register
Search
View: 733|Reply: 4

Writing a simple dialog with VC

[Copy link]

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-3-21 14:00:01
| Show all posts |Read mode
Create two buttons and two ListBox data display boxes on the dialog box.
One is to read the data from the excel table and display the contents of the excel table in a ListBox. The other button is to read the data from the excel table to implement the calculation of least squares and put the result in another ListBox Display.
Because I'm using the MFC framework in Visual C ++ for the first time, I don't understand a lot of things, and I read a lot of articles on the Internet, but I always make mistakes. Which teacher would like to help.
The calculation procedure is better for me.
#include <stdio.h>
#include <math.h>
#define N 1000000
#define H 100
#define E 0.0001
float A [H] [H];
float _A [H] [H];
float x [H];
float x0 [H];
float A_A [H] [H];
float b [H];
float B [H];
int n;
int m;

float Sumax (int n, int i, float x0 [])
{
  int j;
  float result;
  result = 0;
  for (j = 0; j <n; j ++)
  result + = A_A [i] [j] * x0 [j];
  return result;
}
float Maxof (float x [], float x0 [], int n)
{
  int i;
  float result;
  result = 0;
  for (i = 0; i <n; i ++)
  {
if (result <fabs (x [i] -x0 [i]))
result = fabs (x [i] -x0 [i]);
  }
  return result;
}
void Jacobiagrithm (float b [], int n, float x [], float e)
{
int i, k;

float R;
    for (i = 0; i <n; i ++)
x0 [i] = 0;
for (k = 1; k <= N; k ++)
{
for (i = 0; i <n; i ++)
x [i] = x0 [i] + (b [i] -Sumax (n, i, x0)) / A_A [i] [i];
        R = Maxof (x, x0, n);
        if (R <= e) return;
for (i = 0; i <n; i ++)
x0 [i] = x [i];
}

}
void Init ()
{
   int i, j;
float sum;
   scanf ("% d",&m);
   scanf ("% d",&n);
   for (i = 0; i <m; i ++)
for (int j = 0; j <n; j ++)
scanf ("% f",&A [i] [j]);
   for (i = 0; i <m; i ++)
scanf ("% f",&b [i]);
  // for (i = 0; i <m; i ++)
  // A [i] [j] = 1;
   for (i = 0; i <n; i ++)
for (j = 0; j <m; j ++)
_A [i] [j] = A [j] [i];
   for (i = 0; i <m; i ++)
for (j = 0; j <m; j ++)
{
         sum = 0;
for (int k = 0; k <m; k ++)
if (m> = n)
sum + = _ A [i] [k] * A [k] [j];
else
             sum + = A [k] [j] * _ A [i] [k];
A_A [i] [j] = sum;
}
    for (i = 0; i <m; i ++)
{
sum = 0;
for (int k = 0; k <m; k ++)
if (m> = n)
sum + = _ A [i] [k] * b [k];
else
       sum + = b [k] * _ A [i] [k];
B [i] = sum;
}
   Jacobiagrithm (B, n, x, E);
   for (i = 0; i <n; i ++)
printf ("% f", x [i]);
}
void main ()
{
Init ();

}
Reply

Use magic Report

2

Threads

20

Posts

12.00

Credits

Newbie

Rank: 1

Credits
12.00

 China

Post time: 2020-6-27 16:00:01
| Show all posts
The main function is not possible in MFC
Reply

Use magic Report

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-6-27 21:30:01
| Show all posts
The following program can be run independently.
I don't know how to decompose it and embed it under the Button command of the MFC dialog box, I hope the teacher will give it all.
Reply

Use magic Report

0

Threads

14

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

Post time: 2020-6-28 20:15:01
| Show all posts
With MFC
Reply

Use magic Report

0

Threads

14

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

Post time: 2020-6-28 21:30:02
| Show all posts
Use MFC to add two buttons and two listboxes, and then add the corresponding functions to the corresponding button events. Only one of them reads data from the file and displays it in the listbox. The following is to write data to the file. Search the Internet and read data from the file.
CString strValue;
strValue = "select xx from table ";
CStdioFile f;
if (f.Open( "g:\\a.doc" ,CFile::modeCreate|CFile::modeWrite)))
{
   f.WriteString( strValue );
   f.Close();
}
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list