Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Relevant Programming Concepts: Structures Define the following data type that describes an apartment for lease. typedef struct{ char nbrhd[20]; int bedrooms; int sqft; double rent;

Relevant Programming Concepts:

Structures

Define the following data type that describes an apartment for lease.

typedef struct{

char nbrhd[20];

int bedrooms;

int sqft;

double rent;

} apt_t;

Develop a C program that reads a file called apts.txt into a 10-element array of type apt_t. It then prints all apartments located at UA larger than 1,400 square feet, with a rent lower than $1,500. Your program should use the following functions

void scan_apt(apt_t *x, FILE *in);

void print_apt(apt_t *x);

File apts.txt:

UA 3 1475 1430

Foothills 4 2750 2200

West 3 1780 1275

East 4 1650 1350

UA 4 1850 2100

UA 3 1600 1450

UA 3 1520 1300

Foothills 2 1100 1200

East 3 1700 1350

West 4 2400 1950

Sort the array of apartments in square feet and print the sorted array on screen. To do so, modify the following function that sorts ints

void selection(int x[], int size){ // selection sort

int i, j;

int min;

for (i = 0; i < size; i++){

min = i; // start searching from currently unsorted

for (j = i; j

if (x[j] > x[min]) // if found a smaller element

min = j; // move it to the front

}

swap(&x[i], &x[min]);

}

}

void swap(int *x, int *y){

int temp;

temp = *x;

*x = *y;

*y = temp;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL For Data Science Data Cleaning Wrangling And Analytics With Relational Databases

Authors: Antonio Badia

1st Edition

3030575918, 978-3030575915

More Books

Students also viewed these Databases questions

Question

How will the reader feel upon reading this?

Answered: 1 week ago