×
Failure will never overtake me if my determination to succeed is strong enough.
--Your friends at LectureNotes
Close

Note for Advanced Java Programming - AJP By Shivansh Singh

  • Advanced Java Programming - AJP
  • Note
  • 17 Views
  • Uploaded 6 months ago
Shivansh Singh
Shivansh Singh
0 User(s)
Download PDFOrder Printed Copy

Share it with your friends

Leave your Comments

Text from page-1

PROGARM-1 //Swapping two numbers using pointer. #include<stdio.h> void swap(int *a, int *b); int main() { int m, n; printf("Enter the FIRST Number : "); scanf("%d", &m); printf("\nEnter the SECOND Number : "); scanf("%d", &n); printf("FIRST Number = %d\n",m); printf("SECOND Number = %d\n\n",n); swap(&m,&n); //passing address of m and n to the swap function printf("After swapping:\n\n"); printf("FIRST Number = %d\n",m); printf("SECOND Number = %d",n); return 0; } void swap(int *a, int *b) //pointer a and b holds and points to the address of m and n { int temp; temp = *a; *a = *b; *b = temp; } OUTPUT : Enter the FIRST Number : 18 Enter the SECOND Number : 30 FIRST Number = 18 SECOND Number = 30 After Swapping : FIRST Number = 30 SECOND Number = 18 1

Text from page-2

PROGARM-2 /*WAP to write all the members of an array of structures to a file using fwrite(). Read the array from the file and display on the screen*/ #include<stdio.h> struct student { char name[50]; int height; }; int main() { struct student stud1[5], stud2[5]; FILE *fptr; int i; fptr = fopen("file.txt", "wb"); for(i=0; i<5; ++i) { fflush(stdin); printf("Enter name: "); gets(stud1[i].name); printf("Enter height: "); scanf("%d", &stud1[i].height); } fwrite(stud1, sizeof(stud1), 1, fptr); fclose(fptr); fptr = fopen("file.txt", "rb"); fread(stud2, sizeof(stud2), 1, fptr); for(i=0; i<5; ++i) { printf("Name: %s\tHeight: %d\n", stud2[i].name, stud2[i].height); } fclose(fptr); } OUTPUT: Enter name : ram Enter height : 165 Enter name : Shyam Enter height : 180 Enter name : kumar Enter height : 148 Enter name : madhur Enter height : 155 Enter name : vijay Enter height : 162 2

Text from page-3

name : ram name : Shyam name : Kumar name : Madhur name : vijay height : 165 height : 180 height : 148 height : 155 height : 162 3

Text from page-4

PROGARM-3 //Object and Class in C++ Programming #include<stdio.h> using namespace std; class Test { private: int data1; float data2; public: void insertIntegerData(int d) { data1 = d; printf("Number : %d",data1); } float insertFloatData() { printf("\nEnter data : "); scanf("%f",&data2); return data2; } }; int main() { Test o1, o2; float secondDataOfObject2; o1.insertIntegerData(12); secondDataOfObject2 = o2.insertFloatData(); printf("You entered : %.1f", secondDataOfObject2); return 0; } OUTPUT: Number : 12 Enter data: 25 You entered: 25.0 4

Lecture Notes