A Virginia Tech software engineering class in 2009 was discussing world problems and how computer science might offer solutions when a student piped up with a personal gripe.

“You know what I hate?” the student said, according to assistant professor Eli Tilevich, who was teaching the class. “I never know when the bus is coming.”

As Virginia Tech and other universities train a new generation of computer scientists, professors are asking students to create programs that address real-life problems, often through handy, smartphone-ready apps. It’s a break from traditional coursework such as sorting lists of numbers or re-creating programs that already exist.

The shift comes as the demand for computer engineers outpaces the number of computer science graduates. Today’s students grew up with computers, yet many view computer science and code writing as dull and unglamorous, professors say.

The Virginia Tech student’s concern about buses, Tilevich said, offered a chance to show students that coding can be relevant. By the end of the semester, the advanced software engineering class had partnered with the city transit system to obtain data from Global Positioning System devices on dozens of city buses. An algorithm soon was predicting arrival times and beaming the information to a prototype mobile application.

“Sometimes as faculty members, we have to step back. We have to let them run wild,” said Tilevich, a former professional clarinet player who blogs about his teaching experiments.

Computer and math fields are expected to add 785,700 jobs between 2008 and 2018, a growth rate twice the average for all occupations, according to the U.S. Bureau of Labor Statistics. Computer science majors also will earn higher-than-average salaries.

Yet at Virginia Tech’s computer science job fair last year, there were more open jobs than graduating students, said Barbara G. Ryder, head of the computer science department. “And I don’t think that we’re unusual,” she said.

It wasn’t always like this. In the late 1990s, computer science and computer engineering saw an explosion in enrollment nationwide. Between 1995 and 1997, the number of new computer science students doubled, then continued to grow.

During the 1997-98 school year, there were about 10,000 computer science graduates. By 2003-04, that number was up to nearly 21,000, according to the Computing Research Association’s annual survey of computer science and engineering programs. But then came the dot-com bubble burst and news of technology jobs being sent overseas. By 2006-07, the number of graduates was down to about 12,500. Numbers have ticked up since then, but not by much.

Despite the celebrity of Facebook founder Mark Zuckerberg, computer science is sometimes associated with the boring, humorless programmers in the cartoon strip “Dilbert” or the forgettable ones in the Facebook movie “The Social Network,” who wire themselves into computers while ignoring the world around them.

The problems start in high school. In many districts, computer science is taught through vocational departments, often along with shop class. The NCAA doesn’t recognize computer science as a core course when determining the academic eligibility of student athletes. Computer science also was among the least-taken Advanced Placement tests, with fewer than 19,400 students taking it in 2010. (Chemistry, biology and calculus had test takers in the six digits.)

“The sky is falling in a sense that we’re not engaging kids that we could be engaging,” said Jan Cuny of the National Science Foundation, who is helping to formulate a new AP course. While the current program focuses mostly on Java programming, a new class being piloted at several colleges would focus on problem-solving and creating technology instead of just using it.

“We’ll have no problem interesting kids in doing these things,” Cuny said. “The tough part is getting into the schools.”

For the past few years at Virginia Tech, the computer science department has sent faculty members and undergraduates on high school recruiting trips across the state and hosted workshops for local teachers. The university also organizes engineering summer camps aimed at girls and underrepresented minority students.

The bus project grew out of an advanced undergraduate class in which Tilevich gave this goal for the semester: Create something incredible. Either everyone was going to get an A, or everyone would fail.

The bus tracker app received an A, although it was a prototype when the semester ended, prone to crashing when more than two people tried to use it at the same time.

But then one of the students went to the student government to ask for funding to turn it into a user-friendly program. A candidate for the 2009-10 student presidency, Brandon Carroll, made the bus tracker one of his campaign promises. Carroll won, and the student government voted to give the project $34,800 from a T-shirt fundraiser.

Tilevich and Webb recruited two undergraduates to develop what became the user-friendly VT Bus Tracker. It was released at the beginning of this school year as a text-messaging service, a Web site and apps for three types of smartphones. (An included trick: Text “Let’s go,” and the system replies, “Hokies!”)

The bus tracker app receives about 40,000 hits a day, Tilevich said. It also won undergraduate research awards. The developers became campus heroes for saving fellow students from waiting in the elements for longer than necessary.

“The first couple months, when we showed it to people, their jaws dropped,” said one of the developers, Alex Obenauer, a junior computer science major from Woodbridge. “This is such a great way to show what computer science can do.”