Questions
code in C Step 1 Write a program that will read in a list of addresses...

code in C

Step 1

  • Write a program that will read in a list of addresses (100 maximum) from a file.
  • The program should read records from a file until an EOF is found.
  • The program must read one character at a time from the file using fgetc.

For example: chrLetter = fgetc( pfilInput );

  • No partial addresses/records will be given.
  • The format of the addresses is: RecordID, Full Name, Street, City, State, ZipCode

Step 2

  • Store the addresses in an array of structures.
  • Use the typedef below
  • You will have to parse the input lines to separate the fields.
  • You will have to separate full name into first, middle and last name.
  • Trim all leading and trailing whitespace for EACH field.

typedef struct

{

      long lngRecordID;

      char strFirstName[ 50 ];

      char strMiddleName[ 50 ];

      char strLastName[ 50 ];

      char strStreet[ 100 ];

      char strCity[ 50 ];

      char strState[ 50 ];

      char strZipCode[ 50 ];

} udtAddressType;

Step 3

  • Call a subroutine from main and pass the array of structures as a parameter. In the subroutine, load all the addresses from the file into the array of structures.

Step 4

  • Call a subroutine from main and pass the array of structures as a parameter. In the subroutine, print out all the addresses. Make it look pretty. Don’t print out blank records. For example:

------------------------------------------------------------

Customer #1

            First Name:          Luke

            Middle Name:      

            Last Name:          Skywalker

            Address:              123 Elm Street

            City:                    Corusant

            State:                  Ohio

            Zip Code:             45202

------------------------------------------------------------

Customer #2

Extra Credit

  • After you read in the addresses call a subroutine to sort the addresses alphabetically by last name, first name. Try the quick sort in the STL (standard template library).

Extra Extra Credit

  • Eliminate any duplicates addresses (just check street and zip code).

In: Computer Science

C++ language: Class Song The class will have the following private attributes: Title (string) Artist (string)...

C++ language:

Class Song

The class will have the following private attributes:

  • Title (string)
  • Artist (string)
  • Album (string)
  • PlayTime (integer)
  • Year (integer)

It will also have the following public member functions:

  • default constructor setting the playtime to 0 and year to 0.
  • a constructor using Title, Artist, Album, Year, and PlayTime as arguments
  • accessors and mutators for all private attributes
  • a void function 'Play' that will print out the information about the song in the following format (provided)
Playing *Title* by  *Artist*  *playtime* seconds
  • a comparison operator == that uses title, artist and album (but not year and playtime) for comparing two songs.

Implement the missing functions using the template provided.

Class MusicLibrary

MusicLibrary has the following private attributes

  • int maxSongs
  • int numSongs
  • Song * mySongs
  • int numSongsPlayList
    • Song** playList;

Note that mySongs is a pointer that will be used to initialize a dynamic array of songs. You need to handle this dynamic array correctly (e.g. shallow copies, memory deallocation etc.)

playList is a dynamic array of pointers to Songs in the mySongs array.

The class also includes the following public member functions:

  • bool function addSong taking title, artist, album, playtime, year (provided)
  • readSongsFromFile (provided)
    • some accessors (provided)

This class is partially implemented. Complete the following:

  • implement a constructor taking the number of songs as an argument
  • implement a copy constructor
  • implement the public function 'playRandom' which plays all songs of the library ( by invoking the play function of each song) in pseudo-random fashion by alternating songs from the beginning and from the end of the list, until all songs have been played. For example, if the library has 7 songs, the songs will be played in the following order: 0, 6, 1, 5, 2, 4, 3
    • implement the public function addSongToPlayList which stores a pointer to a song in the library in the array of Song pointer. The input to this method is an integer denoting the position of the song in the MusicLibrary

If the Playlist is full, print the following error message

Could not add Song to PlayList. PlayList is full

If the integer denoting the position of a song in the MusicLibrary is invalid, print the following error message

Invalid song
  • implement the public function 'playPlaylist' which plays the songs in the playlist in the same order as the songs have been added to the playlist.

A sample main file has been provided showing the utilization of the functions, as well as a sample input file.

IMPORTANT

  • Classes and methods names must match exactly for unit testing to succeed.
  • Submissions with hard coded answers will receive a grade of 0.

main.cpp:

#include <iostream>

#include <string>

#include "Song.h"

#include "MusicLibrary.h"

using namespace std;

int main()

{

string filename;

int numsongs;

cout << "Enter number of Songs " << endl;

cin >> numsongs;

cout << "Enter filename with information about the songs" << endl;

cin >> filename;

MusicLibrary mylibrary(numsongs);

mylibrary.readSongsFromFile(filename);

mylibrary.playRandom();

for (int i = numsongs-1; i >= 0; i--) {

mylibrary.addSongToPlayList(i);

}

mylibrary.playPlaylist();

return 0;

}

musicLibrary.cpp:

#include <iostream>

#include <fstream>

#include <sstream>

#include <string>

#include "MusicLibrary.h"

MusicLibrary::MusicLibrary(int maxsongs)

{

   // implement constructor

}

MusicLibrary::MusicLibrary(MusicLibrary& other)

{

   // implement copy constructor

}

MusicLibrary::~MusicLibrary()

{

delete[] mySongs;

delete[] playList;

}

int MusicLibrary::getnumSongs()

{

   return numSongs;

}

int MusicLibrary::getmaxSongs()

{

   return maxSongs;

}

int MusicLibrary::getnumSongsPlayList()

{

   return numSongsPlayList;

}

bool MusicLibrary::addSong(string title, string artist, string album, int year, int time)

{

if (numSongs == maxSongs) {

cout << "Could not add song to library. Library is full" << endl;

return false;

}

mySongs[numSongs].setTitle(title);

mySongs[numSongs].setArtist(artist);

mySongs[numSongs].setAlbum(album);

mySongs[numSongs].setYear(year);

mySongs[numSongs].setPlayTime(time);

numSongs++;

return true;

}

bool MusicLibrary::addSong(Song& song)

{

if (numSongs == maxSongs) {

cout << "Could not add Ssong to library. Library is full" << endl;

return false;

}

mySongs[numSongs] = song;

numSongs++;

return true;

}

void MusicLibrary::readSongsFromFile(string filename)

{

ifstream input;

input.open(filename);

bool cont = true;

if (input.is_open()) {

string line;

while ( getline(input, line) && cont ) {

string title, artist, album;

string s_year, s_time;

int year;

int time;

istringstream inSS(line);

getline(inSS, title, ',');

getline(inSS, artist, ',');

getline(inSS, album, ',');

getline(inSS, s_year, ',');

getline(inSS, s_time);

year = stoi(s_year);

time = stoi(s_time);

cont = addSong(title, artist, album, year, time);

};

}

else {

cout << "could not open file " << filename << endl;

}

}

void MusicLibrary::playRandom()

{

   // implement this method

}

bool MusicLibrary::addSongToPlayList(int pos)

{

// implement this method

}

void MusicLibrary::playPlaylist()

{

   // implement this method

}

musicLibrary.h:

#pragma once

#include <string>

#include "Song.h"

using namespace std;

class MusicLibrary

{

private:

int maxSongs;

int numSongs; // number of Songs in library

Song* mySongs; // dynamic array storing all Songs

int numSongsPlayList; // number of Songs in Playlist

Song** playList; // dynamic array of pointers to Songs

public:

MusicLibrary(int maxsongs);

MusicLibrary(MusicLibrary& other);

~MusicLibrary();

   int getnumSongs();

   int getmaxSongs();

   int getnumSongsPlayList();

bool addSong(string title, string artist, string album, int year, int time);

bool addSong(Song& song);

void readSongsFromFile(string filename);

bool addSongToPlayList(int pos);

void playRandom();

void playPlaylist();

};

song.cpp:

#include <iostream>

#include "Song.h"

void Song::Play()

{

cout << "Playing "<< Title << " by " << Artist << " " << PlayTime << " seconds" << endl;

}

// Add code for constructors, accessors, mutators, and == operator.

song.h:

#pragma once

#include <string>

using namespace std;

class Song {

private:

string Title;

string Artist;

string Album;

int Year;

int PlayTime;

public:

   // Add declaration for constructors, accessors and mutators

   // Add declaration for overloading the == operator

void Play();

};

songs.txt:

Zoo Station, U2, Achtung Baby, 1991, 203
Youngblood, 5 Seconds of Summer, Youngblood, 2018, 311
Money for Nothing, Dire Straits, Brothers in Arms, 1986, 501
Summer of 69, Bryan Adams, Reckless, 1984, 178
Livin on a Prayer, Bon Jovi, Slippery when Wet, 1986, 241

In: Computer Science

in simple C++: 2. Create a structure Fraction which contains a numerator and a denominator then...

in simple C++:

2. Create a structure Fraction which contains a numerator and a denominator then do the following:
a. Write a function void printFraction(Fraction f) which prints out a fraction in the following format; e.g. if the numerator is 2 and the denominator is 5, it will print out 2/5
b. Write a function Fraction mult(Fraction f1, Fraction f2) which returns a new fraction which is the product of f1 and f2.
c. Write a function Fraction add(Fraction f1, Fraction f2) which returns a new fraction which is the sum of f1 and f2. You may simply multiply each fraction by the other’s denominator to find a common denominator; e.g. (3/4)+(5/6) = (3*6/4*6)+(5*4/6*4) = 38/24. You do NOT have to reduce the fractions.

In: Computer Science

PYTHON QUESTION Create a subclass of the Dog class named anything appropriate (e.g. Bulldog, Chihuahua, German...

PYTHON QUESTION

Create a subclass of the Dog class named anything appropriate (e.g. Bulldog, Chihuahua, German Shepherd, etc). This subclass should consist of the following:

1. It should inherit the __init__ method from the Dog class, but add one new attribute at instantiation.

2. It should add two new methods that were not in our Dog class

3. It should overwrite one of the methods that existed in the Dog class.

-------

I'm not entirely sure where I should add this information to my dog class, nor how I should go about overwriting one of the methods.

-------

class Dog:
    def __init__(self,name,age):
        self.name = name
        self.age = age

    def description(self):
        return self.name + ' is' + str(self.age) + ' years old.'

    def speak(self):
        return self.name + ' barks!'

    def run(self):
        return self.name + ' is running!'

    def fetch(self, toy):
        print(self.run())
        print(self.name + ' fetched the ' + toy)
        print(self.name + ' is bringing it back!')


    def wags_tail(self):
        return self.name + ' is so happy!'

    def isolder(self, dog2):
        if self.age > dog2.age:
            return True
        else:
            return False

dog1 = Dog('Hurc', 2)
dog2 = Dog('Sammy', 5)
print(dog1.description())
print(dog1.speak())
print(dog1.run())
dog1.fetch('ball')
print(dog1.wags_tail())
print(dog1.isolder(dog2))

In: Computer Science

Do this in python with code that I can copy and run Design and implement class...

Do this in python with code that I can copy and run

Design and implement class Radio to represent a radio object. The class defines the following attributes (variables) and methods:

Assume that the station and volume settings range from 1 to 10.

  1. A private variable of type int named station to represent a station number. Set to
  2. A private variable of type int named volume to represent the volume setting. Set to 1.
  3. A private variable of type boolean named on to represent the radio on or off. Set to false.
  4. A non-argument constructor method to create a default radio.
  5. Method getStation() that returns the station.
  6. Method getVolume() that returns the volume.
  7. Method turnOn() that turns the radio on.
  8. Method turnOff() that turns the radio off.
  9. Method stationUp() that increments the station by 1 only when the radio is on.
  10. Method stationDown() that decrements the station by 1 only when the radio is on.
  11. Method volumeUp() that increment the volume by 1 only when the radio is on.
  12. Method volumeDown() that decrements the volume by 1 only when the radio is on.
  13. Method toString()to printout a meaningful description of the radio as follows(if the radio is on):

The radio station is X and the volume level is Y. Where X and Y are the values of variables station and volume. If the radio is off, the message is: The radio is off.

Now design and implement a test program to create a default radio object and test all class methods on the object in random order. Print the object after each method call and use meaningful label for each method call as shown in the following sample run.

Sample run:

Turn radio on:

The radio station is 1 and the volume level is 1.

Turn volume up by 3:

The radio station is 1 and the volume level is 4.

Move station up by 5:

The radio station is 6 and the volume level is 4.

Turn volume down by 1:

The radio station is 6 and the volume level is 3.

Move station up by 3:

The radio station is 9 and the volume level is 3.

Turn radio off.

The radio is off.

Turn volume up by 2: The radio is off.

Turn station down by 2: The radio is off.

In: Computer Science

1) As a software engineer what are your legal and ethics responsibilities when you work for...

1) As a software engineer what are your legal and ethics responsibilities when you work for medical and military application?

2) What are the two levels of system design? Describe their corresponding main purpose briefly

3) What is double blind test? How to use this test to objectively compare the goodness of two software system, (e.g... google vs Bing.)

4) Define and Describe the main pros and cons of three software cost estimation methods

Compare the following concepts ( state the respective definitions and the difference)

- understandability vs user-friendliness

-software debugging vs. software testing

-black-box testing vs white-box testing

-software re-engineering vs reverse software engineering

In: Computer Science

Describe how you would adapt the RGB color model in WebGL to allow you to work...

Describe how you would adapt the RGB color model in WebGL to allow you to work with a subtractive color model.

In: Computer Science

Cyber Security class 1. Your task is to compute a session key KAB in Diffie-Hellman Key...

Cyber Security class

1. Your task is to compute a session key KAB in Diffie-Hellman Key Exchange (DHKC) with Elliptic Curves. Your private key is a = 6. You receive Bob’s public key B = (5,9). The elliptic curve being used is defined by y2 ≡ x3+x+6 mod 11.

2. In RSA Digital Signature, Suppose Bob wants to send a signed message (x = 4) to Alice. The first steps are exactly the same as it is done for an RSA encryption: Bob computes his RSA parameters and sends the public key to Alice. We know p = 3, q =11, and bob choose e=3. (Hint: We learn RSA algorithm and key generation in Week 7)

(a) What is the public key pair Bob sends to Alice?

(b) What is the value of signature s?

(c) What is the value of verkpubA(x,s)? Show all intermediate steps clearly.

Prove in RSA digital signature, verkpubA(x,s) = x

In: Computer Science

public class ValidBST { class BSTTest<Key extends Comparable<Key>, Value> { private Node root; // root of...

public class ValidBST {


    class BSTTest<Key extends Comparable<Key>, Value> {
        private Node root;             // root of BST

        private class Node {
            private Key key;           // sorted by key
            private Value val;         // associated data
            private Node left, right;  // left and right subtrees

            public Node(Key key, Value val) {
                this.key = key;
                this.val = val;
            }
        }

    }


    public boolean isValidBST(BSTTest bst) {






        return false;
    }

    public static void main(String[] args) {

    }
}

In: Computer Science

Write an AWK program that takes as input salary_file (Imaginary File). The salary_file consists around 150...

Write an AWK program that takes as input salary_file (Imaginary File). The

salary_file consists around 150 records, each record having three fields: name, salary per hour,

and hours worked -- fields 1, 2, and 3, respectively. Save your AWK program in a file. Name the

file according to our standard convention but with .awk extension, hence name it

As5_yourName_p2.awk. Do not forget to have comments inside of your AWK file.

Your AWK program should have all three segments: BEGIN, main (pattern/action), and END

blocks

1. In the BEGIN segment

1. print your name

2. introduce/initiate variables that you are going to use in parts 2. and 3. of this

Problem

2. In the main block/segment, print

1. only names and salaries of employees that earned more than $700.00

2. names of all employees whose names start with capital A, G or W

3. In the END segment, print

1. total number of employees

2. cumulative hours worked by all employees

3. name of the employee that earned the most

4. name of the file that AWK (this program) is processing

In: Computer Science

C++ I have to create printArray, but I have the error " error C2065: 'ar': undeclared...

C++

I have to create printArray, but I have the error " error C2065: 'ar': undeclared identifier". Just need a little help.

#include
#include
#include

using namespace std;

void fillArray(int a[], int size);
void printArray(int a[], int size);


int main()
{
   int ar[10];

   fillArray(ar, 10);
   printArray(ar, 10);

   return 0;
}
void fillArray(int a[], int size)
{
   for(int i = 0; i < 10; i++)
       a[i] = rand() % 10 + 1;
}
void printArray(int a[], int size)
{
   for (int i = 0; i < 10; i++)
       cout << ar[i];
}

In: Computer Science

There are wide applications of the searching algorithm, where given a list of objects, to find...

There are wide applications of the searching algorithm, where given a list of objects, to find whether the search target is in the list.

The intuitive solution is that we walk through the list until the search target is found or the end of the list is reached. The solution is called Linear Search.

For general purpose, let us use ListADT and define a static generic linear search method as follows:

public static <T extends Comparable<T>> int search(ListADT<T> array, T targetValue) throws EmptyCollectionException;

Please implement the linear search method, which walks through the given list and search for the targetValue until the targetValue is found or the end of the list is reached. If the targetValue is found, the method returns the index of the targetValue in the list or else it returns -1.

public static <T extends Comparable<T>> int search(ListADT<T> array, T targetValue) throws EmptyCollectionException {

}

In the hands-out or your sketchbook, please write down your code and take a snapshot and submit it.

Additionally, discuss and answer the following question:

what are the worst and average case running times for serial search?

In: Computer Science

Write a C++ program to check whether a number is prime or not. A prime number...

  1. Write a C++ program to check whether a number is prime or not. A prime number is a positive integer that has exactly two positive integer factors, 1 and itself. Eg: 2, 3, 5, 7, 11, 13, 17, ...

    Sample Output:
    Input a number to check prime or not: 13 The entered number is a prime number.

    Input a number to check prime or not: 28 The entered number is not a prime number.

    Enhance the program to list all factors if the number is not prime Input a number to check prime or not: 28
    The entered number is not a prime number.
    Factors: 1, 2, 4, 7, 14, and 28

In: Computer Science

C++ AVL tree My AVL tree function void inorder(AVLNode* t) { if (t == NULL) return;...

C++ AVL tree

My AVL tree function

void inorder(AVLNode* t)
{
if (t == NULL)
return;
inorder(t->left);
cout << t->data.cancer_rate << " ";
inorder(t->right);
}

void inorder()
{
inorder(root);

}

Will Print my cancer city rate Inorder

example)...you can use any input as long it is a float

3.1

5.8

19.8

22.2

33.3

44.4

[Qustion]

How do I make a function that only prints the last one of my AVLTree ,in this case a function that only prints 44.4

And how do I make a function that only prints the first one of my AVLTree ,in this case a function that only prints 3.1

I think this can be accomplished by editing the inorder function

In: Computer Science

In Java Write a GUI that will let the user sample borders. Include a menu named...

In Java

Write a GUI that will let the user sample borders. Include a menu named Borders that offers three options—beveled border, etched border, and line border—as submenus with the following options:

• Beveled-border submenu options: raised or lowered.

• Etched-border submenu options: raised or lowered.

• Line-border submenu options: small, medium, or large. Each of these options should be a submenu with three color options: black, red, and blue. Put the borders around a label containing text that describes the border, such as Raised Border, Lowered Etched Border, and so forth. Fix the highlight and shadow colors for the etched-border options to whatever colors you like, and make the small line border 5 pixels wide, the medium one 10 pixels wide, and the large one 20 pixels wide.

In: Computer Science