shriman_deepak
Pooja would like to withdraw X $US from an ATM. The cash machine will only accept the transaction if X is a multiple of 5, and Pooja's account balance has enough cash to perform the withdrawal transaction (including bank charges). For each successful withdrawal the bank charges 0.50 $US. Calculate Pooja's account balance after an attempted transaction.
Lucas
Hi everyone. I'm trying to create a struct that stores a dynamically allocated 2D matrix in a variable and its dimensions
This is what I tried:
typedef struct mat_type{
double ** m;
int tamx, tamy;
} mat_type;
``
void createMatrix(mat_type * mat, int tx, int ty){
mat->m = (double **) malloc(tx*sizeof(double*));
for (int i=0; i<tx; i++){
mat->m[i] = (double*) malloc(ty*sizeof(double));
for (int j=0; j<ty; j++){
mat->m[i][j] = 0.0;
}
}
mat->tamx = tx;
mat->tamy = ty;
}
``
mat_type * matrixTest;
createMatrix(matrixTest, 5, 5);
I'm getting segfault.
Nank
#include"Etudiants.h"
#include <stdio.h>
#include <stdlib.h>
//enter the data of a student
Student readStudent(){
Student E;
printf("Name : ");
scanf("%s", E.name);
printf("Surname : ");
scanf("%s", E.surname);
printf("Identifiant : ");
scanf("%s", E.username);
printf("Notes cc : ");
scanf("%d", &E.scoreCc);
printf("Notes Ex : ");
scanf("%d", &E.scoreEx);
printf("\n");
return E;
}
//read the data of a student
void printStudent(Student E){
printf("Name : %s \tSurname : %s\tusername : %s\tscoreCc : %d\tscoreEx : %d", E.name, E.surname, E.username, E.scoreCc, E.scoreEx);
printf("\n");
}
//enter the data of 10 students in a table
Student readTabStudent(){
Student E;
for(int i = 0; i < 2; i++)
readStudent();
return E;
}
//read the data of 10 students in a table
void printTabStudent(Student E){
for(int i = 0; i < 2; i++)
printStudent(E);
}
Spirit
class A {
public:
A() {
try {
b = new B();
} catch (std::bad_alloc) {
cerr << "Couldn't create b.\n";
}
};
~A();
};
class B {
public:
B() {
try {
c = new C();
throw(bad_alloc());
} catch (std::bad_alloc) {
cerr << "Couldn't create c.\n";
throw(std::bad_alloc());
}
};
~B();
C *c;
};
int main() {
A *a = new A();
return 0;
};
Shubh
#include <stdio.h>
#include <conio.h>
#include <string.h>
struct date
{
int d,m,y;
};
struct student
{
char name[50];
int rollno;
char divi[50];
float marks;
char mobile_no[50];
};
struct st2
{
char name2[40];
int rollno_1;
char divi_1[40];
float marks_1;
char mobile_no_1[40];
};
struct date_1
{
int d,m,y;
};
int main ()
{
struct student s;
printf ("Enter the first student information: ");
printf ("\nEnter the name of the student: ");
scanf ("%[^\n]",s.name);
printf ("Enter the roll numner of the student: ");
scanf ("%d",&s.rollno);
printf ("Enter the division of the student: ");
scanf ("%s",s.divi);
printf ("Enter the marks of the student: ");
scanf ("%f",&s.marks);
printf ("Enter the mobile number of the student: ");
scanf ("%s",s.mobile_no);
struct date d;
printf ("enter the student Date Of Birth: \n");
printf ("DAY: ");
scanf ("%d",&d.d);
printf ("MONTH: ");
scanf ("%d",&d.m);
printf ("YEAR: ");
scanf ("%d",&d.y);
printf ("----------[%s] racord----------\n",s.name);
printf ("| student name is: %s\n",s.name);
printf ("| student roll no is: %d\n",s.rollno);
printf ("| student division is: %s\n",s.divi);
printf ("| student marks is: %f\n",s.marks);
printf ("| student nmobile number is: %s\n",s.mobile_no);
printf ("| student birth date is: %d/%d/%d\n",d.d,d.m,d.y);
struct st2 f;
printf ("Enter the Second student information: \n");
printf ("Enter the name of the student: \n");
scanf ("%[^\n]",f.name2);
printf ("Enter the roll number of the student: ");
scanf ("%d",&f.rollno_1);
printf ("Enter the division of the student: ");
scanf ("%s",f.divi_1);
printf ("Enter the marks of the student: ");
scanf ("%f",&f.marks_1);
printf ("Enter the mobile number of the student: ");
scanf ("%s",f.mobile_no_1);
struct date_1 b;
printf ("enter the student Date Of Birth: \n");
printf ("DAY: ");
scanf ("%d",&b.d);
printf ("MONTH: ");
scanf ("%d",&b.m);
printf ("YEAR: ");
scanf ("%d",&b.y);
printf ("----------[] racord----------\n");
printf ("| student name is: %s\n",f.name2);
printf ("| student roll no is: %d\n",f.rollno_1);
printf ("| student division is: %s\n",f.divi_1);
printf ("| student marks is: %f\n",f.marks_1);
printf ("| student nmobile number is: %s\n",f.mobile_no_1);
printf ("| student birth date is: %d/%d/%d",b.d,b.m,b.y);
return 0;
}