BLACKSBURG, VA. - 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.)