Hasnain
Hasnain
Develop a C program to display Name, Roll Number, Date of Birth and Date of
Admission details of a student read from the keyboard where the date of birth and date of
admission further consists of three members such as day, month, and year in a separate
structure. Implement using a C structure.
*/
#include <stdio.h>
struct Date {
int day;
int month;
int year;
};
struct Student {
char name[50];
int rollNumber;
struct Date dob; // Date of Birth
struct Date doa; // Date of Admission
};
int main() {
struct Student student;
printf("Enter Name: ");
scanf("%s", student.name);
printf("\nStudent Details:\n");
printf("Name: %s\n", student.name);
printf("Roll Number: %d\n", student.rollNumber);
printf("Date of Birth: %02d/%02d/%d\n", student.dob.day, student.dob.month,
student.dob.year);
printf("Date of Admission: %02d/%02d/%d\n", student.doa.day, student.doa.month,
student.doa.year);
return 0;
}
Output 1:
Enter Name: Mithun
Enter Roll Number: 69
Enter Date of Birth (DD MM YYYY): 12 03 2005
Enter Date of Admission (DD MM YYYY): 12 08 2023
Student Details:
Name: Mithun
Roll Number: 69
Date of Birth: 12/03/2005
Date of Admission: 12/08/2023
Output 2:
Enter Name: Puneet
Enter Roll Number: 35
Enter Date of Birth (DD MM YYYY): 21 06 1900
Enter Date of Admission (DD MM YYYY): 12 03 2304
Student Details:
Name: Puneet
Roll Number: 35
Date of Birth: 21/06/1900
Date of Admission: 12/03/2304
/*16. Develop a C program to find total and average sales of 'N' employees by reading the
details such as empcode, name, and sales using array of structures.
*/
#include <stdio.h>
struct Employee {
int empCode;
char name[50];
float sales;
};
int main() {
int numEmployees;
float totalSales = 0, averageSales;
printf("Name: ");
scanf("%s", employees[i].name);
printf("Sales: ");
scanf("%f", &employees[i].sales);
totalSales += employees[i].sales;
}
averageSales = totalSales / numEmployees;
printf("\nTotal Sales: %.2f\n", totalSales);
printf("Average Sales: %.2f\n", averageSales);
return 0;
}
Output 1:
Enter the number of employees: 2
Output 2:
Enter the number of employees: 3
*/
#include <stdio.h>
int main() {
int numItems;
float totalCost = 0;
printf("Quantity: ");
scanf("%d", &items[i].quantity);
printf("Rate: ");
scanf("%f", &items[i].rate);
return 0;
}
Output 1:
Enter the number of items: 2
Output 2:
Enter the number of items: 3
*/
#include <stdio.h>
int main() {
struct Employee emp;
return 0;
}
Output 1:
Enter Name: Sumittar
Enter EmpCode: 1212
Enter Salary: 908800
Enter DOB: 14 02 1995
ABC Corporation.
Name: sumittar
EmpCode: 1212
DOB : 14th Feb 1995
Nett. Salary: Rs. 908800.00
Output 2:
Enter Name: Karan
Enter EmpCode: 4543
Enter Salary: 340000
Enter DOB: 12 12 1990
ABC Corporation.
Name: Karan
EmpCode: 4543
DOB: 12th Dec 1990
Nett. Salary: Rs. 340000.00
/* 19. Write a C program to create a file ThreeParas.txt and write any three paragraphs of
textto it. Display the content of the file and the count of frequency of consonants and vowels
present in it to the console.
Note: You may assume a single paragraph in the input stream until you encounter a
newline character ( \n).
*/
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
int main() {
FILE *fp;
char text[] = "This is the first paragraph.\nThis is the second paragraph.\nAnd this is the
third paragraph.\n";
fp = fopen("ThreeParas.txt", "w");
if (fp == NULL) {
printf("Error opening file.\n");
return 1;
}
fprintf(fp, "%s", text);
fclose(fp);
fp = fopen("ThreeParas.txt", "r");
if (fp == NULL) {
printf("Error opening file.\n");
return 1;
}
printf("Content of the file:\n");
char c;
while ((c = fgetc(fp)) != EOF) {
putchar(c);
}
fclose(fp);
fp = fopen("ThreeParas.txt", "r");
if (fp == NULL) {
printf("Error opening file.\n");
return 1;
}
printf("\n\nFrequency of vowels and consonants:\n");
countVowelsAndConsonants(fp);
fclose(fp);
return 0;
}
Output1:
Content of the file:
This is the first paragraph.
This is the second paragraph.
And this is the third paragraph.
*/
#include <stdio.h>
#include <stdlib.h>
int main() {
FILE *sourceFile, *destinationFile;
char sourceFileName[100], destinationFileName[100];
char ch;
fclose(destinationFile);
return 0;
}
Output :
Enter the source file name: source.txt
Enter the destination file name: copy.txt
Contents copied successfully without spaces.
Contents of copy.txt:
Hi,mynameisXYZ
/*21. Implement a C program to read 20 integers through command line arguments and store
them into a file Numbers.txt in the current working path. Then read the file Numbers.txt and
separate them into two different files odd.txt and even.txt such that odd numbers are copied
to odd.txt and even numbers are copied to even.txt files respectively in the same current
working path.
Name: Mohd Hasnain Khan
Roll No.: 43
Section: C1
Course: B.Tech
Branch: CSE
*/
#include <stdio.h>
#include <stdlib.h>
void main()
{
FILE *numbersFile, *oddFile, *evenFile;
int i = 0, odd, even, integer;
fclose(oddFile);
fclose(evenFile);
fclose(numbersFile);
}
}
SAMPLE INPUT:
Enter the numbers: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
OUTPUT:
File: Numbers.txt: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
File: odd.txt: 1 3 5 7 9 11 13 15 17 19
File: even.txt: 2 4 6 8 10 12 14 16 18 20
SAMPLE INPUT:
Enter the numbers: 10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160 170 180 190 200
OUTPUT:
File: Numbers.txt: 10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160 170 180 190 200
File: odd.txt:
File: even.txt: 10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160 170 180 190 200
/* 22. Design a function in python that returns the real quotient and the remainder to the
calling program. Display the quotient and the remainder to the console.
Sample Input:
Enter two numbers: 628 25
Sample Output:
The quotient is: 25.12
The remainder is: 3
*/
Output:
Enter two numbers: 1088 212
The quotient is: 5.13
The remainder is: 28
Output 2:
Enter two numbers: 1232 12
The quotient is: 102.66
The remainder is: 8
/* 23. Design a function in python that returns the concatenated string and its length to the
calling program. Display the joined string and its length to the console.
Sample Input:
Enter the first string: Tic Tac
Enter the second string: Toe
Sample Output:
The joined string: Tic Tac Toe
Length of new string: 11
*/
def concatenate_strings(str1, str2):
joined_string = str1 + " " + str2
length = len(joined_string)
return joined_string, length
# Sample Input
str1 = input("Enter the first string: ")
str2 = input("Enter the second string: ")
# Display results
print("The joined string:", joined_string)
print("Length of new string:", length)
Output 1:
Enter the first string: tic tac
Enter the second string: toe
The joined string: tic tac toe
Length of new string: 11
Output 2:
Enter the first string: akkad bakkad bambe
Enter the second string: bo
The joined string: akkad bakkad bambe bo
Length of new string: 21
/*24. Develop a program in python to read an entire text file and display the number of special
characters present in it to the screen.
Name: Mohd Hasnain Khan
Roll No.: 43
Section: C1
Course: B.Tech
Branch: CSE
*/
special_characters = "!@#$%^&*()_+[]{}|;:,.<>?`~"
special_char_count = 0
OUTPUT:
Number of special characters: 8
OUTPUT:
Number of special characters: 5
/*25. Write a python program to find all the occurrence of words starting with the letters a, c,
d, g, p and s in a file read from the user to the screen. Assume articles or single letters also as
words. Ignore the case.
*/
def find_words_with_starting_letters(file_path):
# Define the starting letters
starting_letters = {'a', 'c', 'd', 'g', 'p', 's'}
try:
# Open the file in read mode
with open(file_path, 'r') as file:
# Read the file and split its content into words
words = file.read().split()
except FileNotFoundError:
print("File not found. Please check the file path.")
# Example usage:
file_path = input("Enter the path of the text file: ")
find_words_with_starting_letters(file_path)
OUTPUT:
Amidst cityscape a symphony and alleys skyscrapers glass
OUTPUT:
dawn sleepy stirred cobblestone streets glistening dew steam passersby promises delights