السلام عليكم ..
لوسمحتوا عندي سؤال فالسي ++ يتكون من عده خطوات :
اولا: المستخدم يدخل عدد الاعمده والصفوف ومن ثم ادخال قيم للصفوف التي يريدها لتصميم مصفوفه }read element
ثانيا: يقوم البرنامج بعرض المصفوفه التي ادخلها{ display elements
ثالثا : edit element حيث يقوم بتحديد رقم الصف والعمود للقيمه التي يريد تغيرها ويظهر القيمه ومن ثم يكتب القيمه الجديده التي يريد ادخالها
رابعا: display report بحيث يعرض المصفوفه كامل بالقيمه الجديده مع حساب المجموع للاعمده والصفوف
هذه محاولتي بس يطلع لي خطأ فتعريف المصفوفه int[][] x=new int[r][c];
فأتمنى حد يصحح الكود لي ويرسلي كيفية تعريف المصفوفه بالصوره الصحيحه
#include<stdio.h>
#include<conio.h>
#include<iostream.h>
void main()
{
int r,c,choice,row,col;
int total=0,temp=0;
int[][] x;
clrscr();
cout<<":: TASKS ::"<<"\n";
cout<<"[1] Read elements"<<"\n";
cout<<"[2] List elements"<<"\n";
cout<<"[3] Edit elements"<<"\n";
cout<<"[4] Display elements"<<"\n";
cout<<"[5] Exit"<<"\n";
cout<<"Enter a task: ";
cin>>choice;
//press 1 for Read elements
cout<<":: Read elements ::"<<"\n";
cout<<"Enter number of rows: ";
cin>>r;
cout<<"\n";
cout<<" columns: ";
cin>>c;
x=new int[r][c];
//for insert elements of n rows
for(row=0;row<r;row++)
{ cout<<"Enter elements of row "<<(row+1)<<" :";
cout<<"\n";
for(col=0;col<c;col++)
{
cout<<(col+1)<<". ";
cin>>x[row][col];
} }
//for press task 2- list elements
cout<<":: TASKS ::"<<"\n";
cout<<"[1] Read elements"<<"\n";
cout<<"[2] List elements"<<"\n";
cout<<"[3] Edit elements"<<"\n";
cout<<"[4] Display elements"<<"\n";
cout<<"[5] Exit"<<"\n";
cout<<"Enter a task: ";
cin>>choice;
cout<<":: List elements ::"<<"\n";
//for list elements
for(row=0;row<r;row++)
{
for(col=0;col<c;col++)
{
cout<<x[row][col]<<"\t";
}
cout<<"\n";
}
cout<<"\n";
//for press task-3 Edit elements
cout<<":: TASKS ::"<<"\n";
cout<<"[1] Read elements"<<"\n";
cout<<"[2] List elements"<<"\n";
cout<<"[3] Edit elements"<<"\n";
cout<<"[4] Display elements"<<"\n";
cout<<"[5] Exit"<<"\n";
cout<<"Enter a task: ";
cin>>choice;
cout<<":: Edit elements ::"<<"\n";
//for edit specific element
cout<<"Enter details of the element to edit: "<<"\n";
cout<<" rows: ";
cin>>r;
cout<<" column: ";
cin>>c;
cout<<"\n";
//search for element
cout<<" Old element: "<<x[r-1][c-1];
cout<<"\n";
int value;
//to insert new element
cout<<"Enter new element: ";
cin>>value;
x[r-1][c-1]=value;
cout<<"\n";
//for display report
cout<<":: TASKS ::"<<"\n";
cout<<"[1] Read elements"<<"\n";
cout<<"[2] List elements"<<"\n";
cout<<"[3] Edit elements"<<"\n";
cout<<"[4] Display elements"<<"\n";
cout<<"[5] Exit"<<"\n";
cout<<"Enter a task: ";
cin>>choice;
cout<<":: Display a report ::"<<"\n";
cout<<"\t\t\t\t\t\t\ttotal";
//for display the new array with total
int rt[]=new int[row];
int ct[]=new int[col];
for(r=0;r<row;r++)
{
for(c=0;c<col;c++)
{
//for find total of rows
rt[r]=rt[r]+x[r][c];
} }
//for find total of columns
for(c=0;c<col;c++)
{
for(r=0;r<row;r++)
{
ct[c]=ct[c]+x[r][c];
} }
//for total
for(c=0;c<col;c++)
{
total=total+ct[c];
}
//to display new array with total
for(r=0;r<row;r++)
{
for(c=0;c<col;c++)
{
cout<<"\t"<<x[r][c]<<"\t";
}
//display total of row
cout<<"\t";
cout<<rt[r];
cout<<"\n";
}
//display total of column
cout<<"-----------------------------------------------------\n";
cout<<"Total"<<"\t";
for(c=0;c<col;c++)
{
cout<<ct[c]<<"\t\t";
}
cout<<total;
cout<<"\n";
//display max element
for(r=0;r<row;r++)
{
for(c=0;c<col;c++)
{
if(x[r][c]>temp)
{
temp=x[r][c];
}
}
}
cout<<"\n";
cout<<"Highest element: "<<temp;
cout<<"\n";
//display min element
for(r=0;r<row;r++)
{
for(c=0;c<col;c++)
{
if(x[r][c]<temp)
{
temp=x[r][c];
}
}
}
cout<<"Lowest element: "<<temp;
cout<<"\n";
//for exit
cout<<":: TASKS ::"<<"\n";
cout<<"[1] Read elements"<<"\n";
cout<<"[2] List elements"<<"\n";
cout<<"[3] Edit elements"<<"\n";
cout<<"[4] Display elements"<<"\n";
cout<<"[5] Exit"<<"\n";
cout<<"Enter a task: ";
cin>>choice;
getch();
}تحيااتــي


